-
Notifications
You must be signed in to change notification settings - Fork 174
Description
I'm looking to replace my SWIG generated and ManagedCuda wrappers for CUDA with a ClangSharp-generated wrapper (SWIG rules are just to arcane). ClangSharpPInvokeGenerator looks promising, but there are several issues:
-
ClangSharp seems to be in two locations: https://github.com/Microsoft/ClangSharp and as a sub project in LLVM https://github.com/Microsoft/LLVMSharp/tree/master/tools/ClangSharpPInvokeGenerator
Which is it? I assume https://github.com/Microsoft/ClangSharp is the correct source as it was more recently updated. -
In cuda.h, there are many typedef declarations, for example:
typedef enum CUaddress_mode_enum { CU_TR_ADDRESS_MODE_WRAP = 0, /**< Wrapping address mode */ CU_TR_ADDRESS_MODE_CLAMP = 1, /**< Clamp to edge address mode */ CU_TR_ADDRESS_MODE_MIRROR = 2, /**< Mirror address mode */ CU_TR_ADDRESS_MODE_BORDER = 3 /**< Border address mode */ } CUaddress_mode;
The generator handles the enum, but not the typedef. A "using ... = ..." might be appropriate.
- The generator does not handle C unions, nor anonymous types well. In cuda.h, there is the following decl:
union { struct { CUarray hArray; /**< CUDA array */ } array; struct { CUmipmappedArray hMipmappedArray; /**< CUDA mipmapped array */ } mipmap; struct { CUdeviceptr devPtr; /**< Device pointer */ CUarray_format format; /**< Array format */ unsigned int numChannels; /**< Channels per array element */ size_t sizeInBytes; /**< Size in bytes */ } linear; struct { CUdeviceptr devPtr; /**< Device pointer */ CUarray_format format; /**< Array format */ unsigned int numChannels; /**< Channels per array element */ size_t width; /**< Width of the array in elements */ size_t height; /**< Height of the array in elements */ size_t pitchInBytes; /**< Pitch between two rows in bytes */ } pitch2D; struct { int reserved[32]; } reserved; } res;
The generator bypasses unions completely. For anonymous structs (e.g., contained in the above union), the generator assigns the name "" as the anonymous type name, but it should make it unique, eg "" + int_id++, because after creating the type, it tests to see if the type was declared previously, and thinks that it was already declared.
I'm planning on a patch for ClangSharp to fix these problems in the next couple days as I'd like to get the tool to work with CUDA asap so I can get back to work on my C#/CIL compiler for GPUs.
Ken Domino