Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ODON1 opened this issue Dec 2, 2021 · 1 comment

Comments

@ODON1
Copy link

ODON1 commented Dec 2, 2021

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 ODON1 changed the title Creaing a cl::coarse_svm_vector<> fails with all types except int on c++17 and 20 Creating a cl::coarse_svm_vector<> fails with all types except int on c++17 and 20 Dec 2, 2021
@MathiasMagnus
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants