[PATCH] D18051: [CUDA] Provide CUDA's vector types implemented using clang's vector extension.

Artem Belevich via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 10 13:30:51 PST 2016


tra added inline comments.

================
Comment at: lib/Headers/__clang_cuda_runtime_wrapper.h:72
@@ -71,1 +71,3 @@
 
+#if defined(CUDA_VECTOR_TYPES)
+// Prevent inclusion of CUDA's vector_types.h
----------------
jlebar wrote:
> Hm, this is a surprising (to me) way of controlling this feature.  Can we use a -f flag instead?  Even if all that -f flag does is define something (although in this case I'd suggest giving it a longer name so it's harder to collide with it).
> 
> -fsomething would be more discoverable and canonical, I think, and would be easier to document.
I want to tweak end-user's view of CUDA headers which has nothing to do with compiler, IMO.

================
Comment at: lib/Headers/__clang_cuda_vector_types.h:76
@@ +75,3 @@
+
+__attribute__((host,device))
+struct dim3 {
----------------
jlebar wrote:
> I thought host/device attributes weren't needed on classes, only functions?
Ugh. Removed.

================
Comment at: lib/Headers/__clang_cuda_vector_types.h:80
@@ +79,3 @@
+  __attribute__((host, device))
+  dim3(unsigned __x = 1, unsigned __y = 1, unsigned __z = 1)
+      : x(__x), y(__y), z(__z) {}
----------------
jlebar wrote:
> Nit: double underscore is a little weird here, and sort of needlessly competes with the language-reserved __ identifier namespace.  Could we just use one underscore?
I'm following the change Eric made to other headers in r260647 so that all arguments use __.

================
Comment at: lib/Headers/__clang_cuda_vector_types.h:82
@@ +81,3 @@
+      : x(__x), y(__y), z(__z) {}
+  __attribute__((host, device)) explicit dim3(uint3 __a)
+      : x(__a.x), y(__a.y), z(__a.z) {}
----------------
jlebar wrote:
> nvidia's version of this function is not explicit -- is this difference intentional?
That's due to the way vector types are their base types with attribute. Without explicit dim3 variant, compiler can't disambiguate between dim3(int=1,int=1,int=1) and dim3(uint3 which is int w/ attribute).

================
Comment at: lib/Headers/__clang_cuda_vector_types.h:84
@@ +83,3 @@
+      : x(__a.x), y(__a.y), z(__a.z) {}
+  __attribute__((host, device)) operator uint3(void) { return {x, y, z}; }
+};
----------------
jlebar wrote:
> This requires C++11 -- is that intentional?
It looks that way, but it does not need c++11. [[ http://clang.llvm.org/docs/LanguageExtensions.html#vector-literals | Vector literals ]] allow brace initializers w/o requiring c++11. 


http://reviews.llvm.org/D18051





More information about the cfe-commits mailing list