Intel® oneAPI Base Toolkit
Support for the core tools and libraries within the base toolkit that are used to build and deploy high-performance data-centric applications.
419 Discussions

std::vector with USM allocator compile error

Jamil_A_
Beginner
1,513 Views

 

Hi 

   Calling shrink_to_fit() on a std::vector that uses the usm_allocator fails to compile.

#include <vector>

#include <CL/sycl.hpp>

using namespace sycl;

const int size = 10;

int main() {
queue q;

// USM allocator for data of type int in shared memory
typedef usm_allocator<int, usm::alloc::shared> vec_alloc;
// Create allocator for device associated with q
vec_alloc myAlloc(q);
// Create std vectors with the allocator
std::vector<int, vec_alloc >
a(size, myAlloc);

a.shrink_to_fit();

return 0;
}

> dpcpp -fsycl usm_test.cpp

In file included from usm_test.cpp:1:
In file included from /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/vector:62:
In file included from /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_construct.h:61:
In file included from /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/ext/alloc_traits.h:36:
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/alloc_traits.h:554:7: error: no matching function for call to 'swap'
swap(__one, __two);
^~~~
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/alloc_traits.h:566:7: note: in instantiation of function template specialization 'std::__do_alloc_on_swap<cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>>' requested here
__do_alloc_on_swap(__one, __two, __pocs());
^
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/ext/alloc_traits.h:98:12: note: in instantiation of function template specialization 'std::__alloc_on_swap<cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>>' requested here
{ std::__alloc_on_swap(__a, __b); }
^
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_vector.h:1236:17: note: in instantiation of member function '__gnu_cxx::__alloc_traits<cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>>::_S_on_swap' requested here
_Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
^
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/allocator.h:232:24: note: in instantiation of member function 'std::vector<int, cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>>::swap' requested here
__c.get_allocator()).swap(__c);
^
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/vector.tcc:609:48: note: in instantiation of member function 'std::__shrink_to_fit_aux<std::vector<int, cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>>, true>::_S_do_it' requested here
return std::__shrink_to_fit_aux<vector>::_S_do_it(*this);
^
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_vector.h:742:9: note: in instantiation of member function 'std::vector<int, cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>>::_M_shrink_to_fit' requested here
{ _M_shrink_to_fit(); }
^
usm_test.cpp:20:5: note: in instantiation of member function 'std::vector<int, cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>>::shrink_to_fit' requested here
a.shrink_to_fit();
^
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/move.h:210:5: note: candidate template ignored: could not match '_Tp [_Nm]' against 'cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>'
swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
^
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_pair.h:495:5: note: candidate template ignored: could not match 'pair' against 'usm_allocator'
swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
^
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_pair.h:503:5: note: candidate template ignored: could not match 'pair' against 'usm_allocator'
swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
^
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/move.h:187:5: note: candidate template ignored: requirement '__and_<std::__not_<std::__is_tuple_like<cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>>>, std::is_move_constructible<cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>>, std::is_move_assignable<cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>>>::value' was not satisfied [with _Tp = cl::sycl::usm_allocator<int, cl::sycl::usm::alloc::shared, 4>]
swap(_Tp& __a, _Tp& __b)
^
1 error generated.

0 Kudos
4 Replies
GouthamK_Intel
Moderator
1,494 Views

Hi,

Thanks for reaching out to us!

We are forwarding this thread to the concerned internal team.

Have a Good day!


Thanks & Regards

Goutham


0 Kudos
cw_intel
Moderator
1,481 Views

Maybe it is a bug need to be fixed. Have escalated it to the development team.


0 Kudos
cw_intel
Moderator
1,307 Views

Hi Jamil,


This issue has been fixed in the latest compiler (2021.3). You can download and install the latest oneAPI from website https://software.intel.com/content/www/us/en/develop/tools/oneapi/base-toolkit/download.html?operatingsystem=linux&distributions=webdownload.

I have verified with the latest compiler. Could you verify again?


Thanks.


0 Kudos
cw_intel
Moderator
1,298 Views

We haven't heard back from you for a long time, and this issue has been fixed in the new compiler. We will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.


0 Kudos
Reply