diff --git a/include/ircd/gpt/vector.h b/include/ircd/gpt/vector.h index fd97bf619..755ba95fd 100644 --- a/include/ircd/gpt/vector.h +++ b/include/ircd/gpt/vector.h @@ -11,22 +11,6 @@ #pragma once #define HAVE_IRCD_GPT_VECTOR_H -#if !defined(__SIZEOF_FLOAT4__) && defined(__OPENCL_VERSION__) - #define __SIZEOF_FLOAT4__ 16 -#endif - -#if !defined(__SIZEOF_FLOAT8__) && defined(__OPENCL_VERSION__) - #define __SIZEOF_FLOAT8__ 32 -#endif - -#if !defined(__SIZEOF_FLOAT16__) && defined(__OPENCL_VERSION__) - #define __SIZEOF_FLOAT16__ 64 -#endif - -#ifndef __OPENCL_VERSION__ - #define __constant -#endif - static __constant const uint ircd_gpt_context_tokens = 512, // 1024, ircd_gpt_vector_elems = 768, diff --git a/include/ircd/simt/assert.h b/include/ircd/simt/assert.h new file mode 100644 index 000000000..223844933 --- /dev/null +++ b/include/ircd/simt/assert.h @@ -0,0 +1,31 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2022 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +#pragma once +#define HAVE_IRCD_SIMT_ASSERT_H + +// +// Trapping assert() on supporting platforms. +// + +#if defined(__OPENCL_VERSION__) + #if __OPENCL_VERSION__ >= 200 \ + && !defined(assert) \ + && !defined(NDEBUG) \ + && __has_builtin(__builtin_trap) + #define assert(expr) \ + ({ \ + if(unlikely(!(bool)(x))) \ + __builtin_trap(); \ + }) + #else + #define assert(x) + #endif +#endif diff --git a/include/ircd/simt/portable.h b/include/ircd/simt/portable.h new file mode 100644 index 000000000..9d17a68ab --- /dev/null +++ b/include/ircd/simt/portable.h @@ -0,0 +1,79 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2022 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +#pragma once +#define HAVE_IRCD_SIMT_PORTABLE_H + +// +// Decide the proper form of the restrict qualifier for the platform, if any. +// + +#if defined(__OPENCL_VERSION__) + #if defined(__SPIR) + #define restrict + #elif defined(__cplusplus) + #define restrict __restrict + #endif +#endif + +// +// Decide the proper form of static linkage for the platform +// + +#if defined(__OPENCL_VERSION__) + #if __OPENCL_VERSION__ < 120 + #define static __attribute__((internal_linkage)) + #elif __OPENCL_VERSION__ < 200 + #define static __constant static + #endif +#endif + +// +// When headers are shared between opencl and non-opencl units, address space +// qualifiers may be required for the former and can be ignored for the latter. +// Note this header itself may be included by both opencl and non-opencl units. +// + +#if !defined(__OPENCL_VERSION__) + #define __constant +#endif + +// +// Silently drop calls to printf() on unsupporting platforms; this way we can +// leave the same code unmodified and quietly discard the output. +// + +#if defined(__OPENCL_VERSION__) + #if __OPENCL_VERSION__ < 200 + #define printf(...) + #endif +#endif + +// +// XXX +// + +#if defined(__OPENCL_VERSION__) + #if !defined(__SIZEOF_FLOAT4__) + #define __SIZEOF_FLOAT4__ 16 + #endif +#endif + +#if defined(__OPENCL_VERSION__) + #if !defined(__SIZEOF_FLOAT8__) + #define __SIZEOF_FLOAT8__ 32 + #endif +#endif + +#if defined(__OPENCL_VERSION__) + #if !defined(__SIZEOF_FLOAT16__) + #define __SIZEOF_FLOAT16__ 64 + #endif +#endif diff --git a/include/ircd/simt/simt.h b/include/ircd/simt/simt.h index 8089919b7..1918d0f16 100644 --- a/include/ircd/simt/simt.h +++ b/include/ircd/simt/simt.h @@ -11,6 +11,8 @@ #pragma once #define HAVE_IRCD_SIMT_H +#include "portable.h" +#include "assert.h" #include "broadcast.h" #include "reduce_add.h" #include "reduce_max.h" diff --git a/ircd/gpt_gpu.cl b/ircd/gpt_gpu.cl index feac4a04a..df811acae 100644 --- a/ircd/gpt_gpu.cl +++ b/ircd/gpt_gpu.cl @@ -15,46 +15,10 @@ #include #include #include - -#if !defined(assert) \ -&& !defined(NDEBUG) \ -&& defined(RB_ASSERT_INTRINSIC) \ -&& __has_builtin(__builtin_trap) \ -&& __OPENCL_VERSION__ >= 200 - #define assert(x) ((void)(unlikely(!(bool)(x))? __builtin_trap(): 0)) -#else - #define assert(x) -#endif - -#if defined(__SPIR) - #define restrict -#elif defined(__cplusplus) - #define restrict __restrict -#endif - -#if __OPENCL_VERSION__ < 120 - #define static __attribute__((internal_linkage)) -#elif __OPENCL_VERSION__ < 200 - #define static __constant static -#endif - -#if __OPENCL_VERSION__ < 200 - #define printf(...) -#endif - -#pragma clang attribute push(__attribute__((always_inline)), apply_to = function) -#pragma clang attribute push(__attribute__((internal_linkage)), apply_to = function) #include #include #include #include -#pragma clang attribute pop -#pragma clang attribute pop - -#if __OPENCL_VERSION__ >= 120 - #undef static -#endif - #include //