OpenCL-CLHPP icon indicating copy to clipboard operation
OpenCL-CLHPP copied to clipboard

Creating a cl::coarse_svm_vector<> fails with all types except int on c++17 and 20

Open ODON1 opened this issue 4 years ago • 1 comments

Trying to allocate a vector of floats:

   cl::SVMAllocator<float, cl::SVMTraitCoarse<>> svmAllocFloat;
   cl::coarse_svm_vector<float> p_vbocl(p_vbo_size, 0.0f, svmAllocFloat);

works fine when not setting an -std= flag when compiling (not sure what it uses then) However when setting -std=c++17 or 20 this fails:

❯ clang++ basics2.cpp -lGL -lglfw -lepoxy -lOpenCL -pthread -std=c++17 -o a2-clang.out
In file included from basics2.cpp:14:
In file included from /usr/include/CL/opencl.hpp:574:
In file included from /usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../include/c++/12.0.0/functional:62:
In file included from /usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../include/c++/12.0.0/vector:64:
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../include/c++/12.0.0/bits/stl_vector.h:437:7: error: static_assert failed due to requirement 'is_same<int, float>::value' "std::vector must have the same value_type as its allocator"
      static_assert(is_same<typename _Alloc::value_type, _Tp>::value,
      ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
basics2.cpp:254:34: note: in instantiation of template class 'std::vector<float, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>' requested here
    cl::coarse_svm_vector<float> p_vbocl(p_vbo_size, 0.0f, svmAllocFloat);
                                 ^
1 error generated.

Specifying manually works ok:

    cl::SVMAllocator<float, cl::SVMTraitCoarse<>> svmAllocFloat;
    std::vector<float, cl::SVMAllocator<float, cl::SVMTraitCoarse<>>> p_vbocl(p_vbo_size, 0.0f, svmAllocFloat);

From the Definition at line 3628 of file cl2.hpp:

 3627 template < class T >
 3628 using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;

I guess the hard coded int should be a T? My system cant use the TraitFine SVM so can't test it for those, but from the definition it seems to have the same problem.

Also cl::coarse_svm_vector<int> test(10, 0.0f, svmAlloc); just works (initializing an int array with floats?)

ODON1 avatar Dec 02 '21 10:12 ODON1

Thank you for your observation. You're most likely right and the wrapper will be needing a fix.

MathiasMagnus avatar Jan 03 '22 12:01 MathiasMagnus