ddemidov / vexcl

VexCL is a C++ vector expression template library for OpenCL/CUDA/OpenMP
http://vexcl.readthedocs.org
MIT License
701 stars 81 forks source link

is_cl_native does not work with SFINAE #102

Closed bmerry closed 10 years ago

bmerry commented 10 years ago

Attempting to instantiate vex::is_cl_native causes this error:

/home/bruce/devel/vexcl/vexcl/types.hpp:317:63: error: ‘value’ is not a member of ‘vex::cl_vector_length<bool>’
         is_cl_native<T>::value && (cl_vector_length<T>::value > 1)

This makes it unusable within enable_if tests. I haven't tested it, but I think the right fix is to define the general case to subclass false_type and use enable_if to specialize the appropriate cases to subclass true_type.

ddemidov commented 10 years ago

The problem here is not is_cl_native, but cl_vector_length, which is unspecialized for bool, which is a non-cl-native type. Are you by any chance trying to use a vex::vector<bool>?

bmerry commented 10 years ago

Actually I'm writing a header to allow vex to work with clogs (which has a much faster autotuned implementation of exclusive scan) so I'm doing metaprogramming to determine whether a type is supported by clogs. I'll send you a pull request when I think it is ready. This only came up in tests I wrote for my traits types (i.e. an assertion that clogs_is_scannable<bool> is false). I've worked around it, but I filed the bug because normally traits classes of the form is_xxx<T> are instantiable for any T.

ddemidov commented 10 years ago

Well, is_cl_native<bool>::value is defined and returns false. It's the second part of the SFINAE check from your example that gives the compilation error.

ddemidov commented 10 years ago

Btw, could you give me a link to clogs? I have never heard of the library. Update: found it.

bmerry commented 10 years ago

Well, is_cl_native<bool>::value is defined and returns false. It's the second part of the SFINAE check from your example that gives the compilation error.

Indeed. The code that fails is in the implementation of is_cl_vector, and hence any instantiation of is_cl_vector<bool> causes a compilation error instead of becoming false_type.

Btw, could you give me a link to clogs? I have never heard of the library.

http://clogs.sourceforge.net (I am the author).

ddemidov commented 10 years ago

Ok, I understand the problem now. The patch is incoming.

clogs looks like an interesting library! Out of interest, how faster is its implementation of inclusive scan than the one from VexCL? Btw, the VexCL version was adopted from AMD Bolt code.

bmerry commented 10 years ago

It only does exclusive scan, not inclusive. On a GeForce 480 GTX it is about 3-4 times faster. I thought it was about 2x faster on my R9 270, but now it seems to only be 15% faster. I'll need to check if some of the recent changes I've made to clogs to make it easier to integrate with vexcl have damaged performance.

ddemidov commented 10 years ago

That sounds nice! The problem with is_cl_vector and is_cl_scalar should be fixed by 1801b6f.

bmerry commented 10 years ago

Yes, that seems to have fixed it. That was quick work, thanks!