diff --git a/include/ircd/simt/math.h b/include/ircd/simt/math.h new file mode 100644 index 000000000..5bbcacfd0 --- /dev/null +++ b/include/ircd/simt/math.h @@ -0,0 +1,20 @@ +// 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_MATH_H + +#ifdef __OPENCL_VERSION__ +inline bool +ircd_math_is_pow2(const uint val) +{ + return val > 0 && (val & (val - 1)) == 0; +} +#endif diff --git a/include/ircd/simt/reduce_add.h b/include/ircd/simt/reduce_add.h index eb2406325..ff7203e36 100644 --- a/include/ircd/simt/reduce_add.h +++ b/include/ircd/simt/reduce_add.h @@ -11,14 +11,6 @@ #pragma once #define HAVE_IRCD_SIMT_REDUCE_ADD_H -#ifdef __OPENCL_VERSION__ -inline bool -ircd_math_is_pow2(const uint val) -{ - return val > 0 && (val & (val - 1)) == 0; -} -#endif - #ifdef __OPENCL_VERSION__ /// Sum all elements in the buffer. All threads in the group participate; /// result is placed in index [0], the rest of the buffer is trashed. diff --git a/include/ircd/simt/simt.h b/include/ircd/simt/simt.h index d9148858e..e86433514 100644 --- a/include/ircd/simt/simt.h +++ b/include/ircd/simt/simt.h @@ -14,6 +14,7 @@ #include "portable.h" #include "assert.h" #include "cycles.h" +#include "math.h" #include "broadcast.h" #include "reduce_add.h" #include "reduce_max.h" diff --git a/include/ircd/simt/sort.h b/include/ircd/simt/sort.h index d969cbf54..83e5fbf8d 100644 --- a/include/ircd/simt/sort.h +++ b/include/ircd/simt/sort.h @@ -66,6 +66,8 @@ ircd_simt_sort_idx16_flldr(__local ushort *const idx, const uint ln, const uint li) { + assert(ircd_math_is_pow2(ln)); + #pragma clang loop unroll(disable) for(uint up = 1; up < ln; up <<= 1) {