summaryrefslogtreecommitdiffstats
path: root/prelude
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-06-10 14:57:09 -0400
committerGitHub <noreply@github.com>2021-06-10 11:57:09 -0700
commit37e8917d10626b519470f2e34625f0efe741352f (patch)
tree4e8e51bd63ebc03fcdf0c893b675906cf507d73c /prelude
parent0d9bd79e8fd4d57e1a723ca6b6a45efec2b42872 (diff)
CUDA layout corner cases/testing (#1881)
* #include an absolute path didn't work - because paths were taken to always be relative. * Add support for sizeOf/alignOf/offsetOf to stdlib. Add $G intrinsic expansion that works of the generic parameters not the param type * Test cuda layout. * Fix CUDA layout issues. Fix reflection to handle other built in types. Fix __offsetOf * Tests of reflection and layout as reported directly from CUDA. * Comment about use of aligned size as size. * Fix warning from VS. * Check alignment is pow2. * Small improvements to alignment calcs. * Tab to spaces. * Fix alignment pointer sizes on 32 bit OS for CUDA. * Fix CUDA reflection on 32 bit.
Diffstat (limited to 'prelude')
-rw-r--r--prelude/slang-cpp-prelude.h75
-rw-r--r--prelude/slang-cuda-prelude.h9
2 files changed, 84 insertions, 0 deletions
diff --git a/prelude/slang-cpp-prelude.h b/prelude/slang-cpp-prelude.h
index 725be4b42..ffd18cf32 100644
--- a/prelude/slang-cpp-prelude.h
+++ b/prelude/slang-cpp-prelude.h
@@ -36,6 +36,81 @@
# define SLANG_INFINITY INFINITY
#endif
+// Detect the compiler type
+
+#ifndef SLANG_COMPILER
+# define SLANG_COMPILER
+
+/*
+Compiler defines, see http://sourceforge.net/p/predef/wiki/Compilers/
+NOTE that SLANG_VC holds the compiler version - not just 1 or 0
+*/
+# if defined(_MSC_VER)
+# if _MSC_VER >= 1900
+# define SLANG_VC 14
+# elif _MSC_VER >= 1800
+# define SLANG_VC 12
+# elif _MSC_VER >= 1700
+# define SLANG_VC 11
+# elif _MSC_VER >= 1600
+# define SLANG_VC 10
+# elif _MSC_VER >= 1500
+# define SLANG_VC 9
+# else
+# error "unknown version of Visual C++ compiler"
+# endif
+# elif defined(__clang__)
+# define SLANG_CLANG 1
+# elif defined(__SNC__)
+# define SLANG_SNC 1
+# elif defined(__ghs__)
+# define SLANG_GHS 1
+# elif defined(__GNUC__) /* note: __clang__, __SNC__, or __ghs__ imply __GNUC__ */
+# define SLANG_GCC 1
+# else
+# error "unknown compiler"
+# endif
+/*
+Any compilers not detected by the above logic are now now explicitly zeroed out.
+*/
+# ifndef SLANG_VC
+# define SLANG_VC 0
+# endif
+# ifndef SLANG_CLANG
+# define SLANG_CLANG 0
+# endif
+# ifndef SLANG_SNC
+# define SLANG_SNC 0
+# endif
+# ifndef SLANG_GHS
+# define SLANG_GHS 0
+# endif
+# ifndef SLANG_GCC
+# define SLANG_GCC 0
+# endif
+#endif /* SLANG_COMPILER */
+
+#define SLANG_GCC_FAMILY (SLANG_CLANG || SLANG_SNC || SLANG_GHS || SLANG_GCC)
+
+// GCC Specific
+#if SLANG_GCC_FAMILY
+# define SLANG_ALIGN_OF(T) __alignof__(T)
+// Use this macro instead of offsetof, because gcc produces warning if offsetof is used on a
+// non POD type, even though it produces the correct result
+# define SLANG_OFFSET_OF(T, ELEMENT) (size_t(&((T*)1)->ELEMENT) - 1)
+#endif // SLANG_GCC_FAMILY
+
+// Microsoft VC specific
+#if SLANG_VC
+# define SLANG_ALIGN_OF(T) __alignof(T)
+#endif // SLANG_VC
+
+// Default impls
+
+#ifndef SLANG_OFFSET_OF
+# define SLANG_OFFSET_OF(X, Y) offsetof(X, Y)
+#endif
+
#include "slang-cpp-types.h"
#include "slang-cpp-scalar-intrinsics.h"
diff --git a/prelude/slang-cuda-prelude.h b/prelude/slang-cuda-prelude.h
index 91094a75e..01c658e0b 100644
--- a/prelude/slang-cuda-prelude.h
+++ b/prelude/slang-cuda-prelude.h
@@ -15,6 +15,15 @@
#include <optix.h>
#endif
+// Define slang offsetof implementation
+#ifndef SLANG_OFFSET_OF
+# define SLANG_OFFSET_OF(type, member) (size_t)((char*)&(((type *)0)->member) - (char*)0)
+#endif
+
+#ifndef SLANG_ALIGN_OF
+# define SLANG_ALIGN_OF(type) __alignof__(type)
+#endif
+
// Must be large enough to cause overflow and therefore infinity
#ifndef SLANG_INFINITY
# define SLANG_INFINITY ((float)(1e+300 * 1e+300))