Type Mapping for C++

May 14, 2020 ยท View on GitHub

grCUDA needs to interact with tree different type systems:

  • The Java types of the Truffle interop protocol (boolean, byte, short, int, long, float, double, String) as described in InteropLibrary. These types are used in the interop with the different GraalVM langauges.
  • C++ language types (see C++ Fundamental Types These types are used to used to bind to GPU kernels as well as to C++ host functions.
  • C interface types from TruffleNFI (void, sint8, uint8, sint16, uint16, sint32, uint32, sint64, uint64, float, double, pointer, object, string). NativeSimpleType.java defines these types. grCUDA uses TruffleNFI to invoke native host functions. While TruffleNFI is designed for C APIs, the C++ types are necessary create the mangled symbols names to invoke with TruffleNFI.

Types for clang/gcc under Linux (LP64)

C++ TypeBytesSymNIDL TypeNFIJava Type
bool1bbooluint8boolean
char1ccharsint8byte
unsigned char1huint8uint8short
signed char1asint8sint8byte
wchar_t4wwcharsint32int
char8_t1Duchar8uint8short
char16_t2Dschar16uint16int
char32_t4Dichar32uint32long
(signed) short2ssint16sint16short
unsigned short2tuint16uint16long
(signed) int4isint32sint32int
unsigned int4juint32uint32long
(signed) long8lsint64sint64long
unsigned long8muint64uint64long+
(singed) long long8xsll64sint64long
unsigned long long8yull64uint64long+
float4ffloatfloatfloat
double8ddoubledoubledouble
long double16e***
void0vvoidvoidvoid
U *8PUinout pointer Vpointern/a
U *8PUout pointer Vpointern/a
const U *8PKUin pointer Vpointern/a
void *8Pvinout pointer voidpointern/a
void *8Pvout pointer voidpointern/a
const void *8PKvin pointer voidpointern/a
const char *8PKcstringstringString

(*) not supported in grCUDA or NFI (+) does not support all values (NFI limitation)

Synonymous NIDL types

Synonymous types are that can substituted without coercion:

  • char, uint8
  • bool, char8, uint8
  • char16, uint16
  • sint32, wchar
  • char32, uint32t
  • sint64, sll64
  • uint64, ull64
  • inout pointer V, out pointer U, synonymous(U, V), inout pointer void, out pointer void
  • in pointer V, in pointer U, synonymous(U, V), in pointer void