31 #include <vector_types.h> 32 #include <vector_functions.h> 33 #include <thrust/iterator/detail/host_system_tag.h> 34 #include <thrust/iterator/detail/device_system_tag.h> 35 #include <thrust/iterator/detail/any_system_tag.h> 38 #define CUGAR_HOST_DEVICE __host__ __device__ 39 #define CUGAR_HOST __host__ 40 #define CUGAR_DEVICE __device__ 42 #define CUGAR_HOST_DEVICE 48 #define CUGAR_RESTRICT __restrict__ 49 #define CUGAR_SHARED __shared__ 51 #define CUGAR_RESTRICT 55 #if defined(__CUDA_ARCH__) && __CUDA_ARCH__ > 0 56 #define CUGAR_DEVICE_COMPILATION 63 #if defined(CUGAR_EXPORTS) 64 #define CUGAR_API __declspec(dllexport) 65 #elif defined(CUGAR_IMPORTS) 66 #define CUGAR_API __declspec(dllimport) 75 #define CUGAR_FORCEINLINE __forceinline 77 #define CUGAR_FORCEINLINE __inline__ 81 #define CUGAR_ALIGN_BEGIN(n) __declspec( align( n ) ) 82 #define CUGAR_ALIGN_END(n) 83 #elif defined(__GNUC__) 84 #define CUGAR_ALIGN_BEGIN(n) 85 #define CUGAR_ALIGN_END(n) __attribute__ ((aligned(n))); 87 #define CUGAR_ALIGN_BEGIN(n) 88 #define CUGAR_ALIGN_END(n) 91 #if defined(CUGAR_CUDA_DEBUG) 92 #define CUGAR_CUDA_DEBUG_STATEMENT(x) x 94 #define CUGAR_CUDA_DEBUG_STATEMENT(x) 97 #if defined(CUGAR_CUDA_ASSERTS) 99 #define CUGAR_CUDA_ASSERT(x) { const bool __yes = true; assert(x && __yes); } 100 #define CUGAR_CUDA_ASSERT_IF(cond, x, ...) if ((cond) && !(x)) {printf(__VA_ARGS__); CUGAR_CUDA_ASSERT(x); } 101 #define CUGAR_CUDA_DEBUG_ASSERT(x,...) if (!(x)) { printf(__VA_ARGS__); CUGAR_CUDA_ASSERT(x); } 102 #elif defined(CUGAR_CUDA_NON_BLOCKING_ASSERTS) // !defined(CUGAR_CUDA_ASSERTS) 103 #define CUGAR_CUDA_ASSERT(x) 104 #define CUGAR_CUDA_ASSERT_IF(cond, x, ...) if ((cond) && !(x)) { printf(__VA_ARGS__); } 105 #define CUGAR_CUDA_DEBUG_ASSERT(x,...) if (!(x)) { printf(__VA_ARGS__); } 106 #else // !defined(CUGAR_NON_BLOCKING_ASSERTS) && !defined(CUGAR_CUDA_ASSERTS) 107 #define CUGAR_CUDA_ASSERT(x) 108 #define CUGAR_CUDA_ASSERT_IF(cond, x, ...) 109 #define CUGAR_CUDA_DEBUG_ASSERT(x,...) 112 #if defined(CUGAR_CUDA_DEBUG) 113 #define CUGAR_CUDA_DEBUG_PRINT(...) printf(__VA_ARGS__) 114 #define CUGAR_CUDA_DEBUG_PRINT_IF(cond,...) if (cond) printf(__VA_ARGS__) 115 #define CUGAR_CUDA_DEBUG_SELECT(debug_val,normal_val) (debug_val) 116 #else // !defined(CUGAR_CUDA_DEBUG) 117 #define CUGAR_CUDA_DEBUG_PRINT(...) 118 #define CUGAR_CUDA_DEBUG_PRINT_IF(cond,...) 119 #define CUGAR_CUDA_DEBUG_SELECT(debug_val,normal_val) (normal_val) 122 #if defined(CUGAR_CUDA_DEBUG) 123 #if defined(CUGAR_CUDA_ASSERTS) 124 #define CUGAR_CUDA_DEBUG_CHECK_IF(cond, check,...) if ((cond) && (!(check))) { printf(__VA_ARGS__); assert(check); } 125 #else // !defined(CUGAR_CUDA_ASSERTS) 126 #define CUGAR_CUDA_DEBUG_CHECK_IF(cond, check,...) if ((cond) && (!(check))) printf(__VA_ARGS__) 128 #else // !defined(CUGAR_CUDA_DEBUG) 129 #define CUGAR_CUDA_DEBUG_CHECK_IF(cond, check,...) 132 #if defined(__CUDACC__) 133 #define CUGAR_HOST_DEVICE_TEMPLATE \ 134 #pragma hd_warning_disable 136 #define CUGAR_HOST_DEVICE_TEMPLATE 146 #ifndef _CRT_SECURE_NO_WARNINGS 147 #define _CRT_SECURE_NO_WARNINGS 1 154 #if defined(__GNUC__) 155 #define CUGAR_VAR_UNUSED __attribute__((unused)) 157 #define CUGAR_VAR_UNUSED 165 typedef unsigned long long uint64;
166 typedef unsigned int uint32;
167 typedef unsigned short uint16;
168 typedef unsigned char uint8;
169 typedef long long int64;
172 typedef signed char int8;
181 struct host_tag :
public thrust::host_system_tag {};
206 template <
typename T>
struct to_const {
typedef T type; };
207 template <
typename T>
struct to_const<T&> {
typedef const T& type; };
208 template <
typename T>
struct to_const<T*> {
typedef const T* type; };
209 template <
typename T>
struct to_const<const T&> {
typedef const T& type; };
210 template <
typename T>
struct to_const<const T*> {
typedef const T* type; };
222 template <
typename T>
struct plain_view_subtype<const T> {
typedef typename T::const_plain_view_type type; };
245 template <
typename T1,
typename T2>
struct same_type {
static const bool pred =
false; };
246 template <
typename T>
struct same_type<T,T> {
static const bool pred =
true; };
250 template <
typename A,
typename B>
255 template <
bool predicate,
typename T,
typename F>
struct if_true {};
256 template <
typename T,
typename F>
struct if_true<true,T,F> {
typedef T type; };
257 template <
typename T,
typename F>
struct if_true<false,T,F> {
typedef F type; };
261 template <
typename A,
typename B,
typename T,
typename F>
struct if_equal 268 template <
typename A,
typename B, u
int32 N>
struct binary_switch {
typedef B type; };
272 template <
typename A,
typename B>
struct binary_switch<A,B,0> {
typedef A type; };
278 template <
typename Out,
typename In>
287 template <
typename Out,
typename In>
290 #if defined(__CUDA_ARCH__) 291 return reinterpret_cast<const Out&
>(in);
299 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
bool is_pow2(
const uint32 C) {
return (C & (C - 1)) == 0u; }
302 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
bool is_pow2_static() {
return (C & (C-1)) == 0u; }
304 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE uint32 next_power_of_two(uint32 v)
316 template <u
int32 N,
typename I> CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
317 I align(
const I a) {
return (N > 1) ? I(a + N-1) & I(~(N-1)) : a; }
320 template <u
int32 N,
typename I> CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
321 I align_down(
const I a) {
return (N > 1) ? I((a / N) * N) : a; }
335 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
336 bool operator==(
const uint2 op1,
const uint2 op2) {
return op1.x == op2.x && op1.y == op2.y; }
340 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
341 bool operator!=(
const uint2 op1,
const uint2 op2) {
return op1.x != op2.x || op1.y != op2.y; }
345 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
346 bool operator==(
const uint3 op1,
const uint3 op2) {
return op1.x == op2.x && op1.y == op2.y && op1.z == op2.z; }
350 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
351 bool operator!=(
const uint3 op1,
const uint3 op2) {
return op1.x != op2.x || op1.y != op2.y || op1.z != op2.z; }
355 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
356 bool operator==(
const uint4 op1,
const uint4 op2) {
return op1.x == op2.x && op1.y == op2.y && op1.z == op2.z && op1.w == op2.w; }
360 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
361 bool operator!=(
const uint4 op1,
const uint4 op2) {
return op1.x != op2.x || op1.y != op2.y || op1.z != op2.z || op1.w != op2.w; }
365 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
366 bool operator==(
const int2 op1,
const int2 op2) {
return op1.x == op2.x && op1.y == op2.y; }
370 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
371 bool operator!=(
const int2 op1,
const int2 op2) {
return op1.x != op2.x || op1.y != op2.y; }
375 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
376 bool operator==(
const int3 op1,
const int3 op2) {
return op1.x == op2.x && op1.y == op2.y && op1.z == op2.z; }
380 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
381 bool operator!=(
const int3 op1,
const int3 op2) {
return op1.x != op2.x || op1.y != op2.y || op1.z != op2.z; }
385 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
386 bool operator==(
const int4 op1,
const int4 op2) {
return op1.x == op2.x && op1.y == op2.y && op1.z == op2.z && op1.w == op2.w; }
390 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
391 bool operator!=(
const int4 op1,
const int4 op2) {
return op1.x != op2.x || op1.y != op2.y || op1.z != op2.z || op1.w != op2.w; }
395 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
396 bool operator==(
const float2 op1,
const float2 op2) {
return op1.x == op2.x && op1.y == op2.y; }
400 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
401 bool operator!=(
const float2 op1,
const float2 op2) {
return op1.x != op2.x || op1.y != op2.y; }
405 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
406 bool operator==(
const float3 op1,
const float3 op2) {
return op1.x == op2.x && op1.y == op2.y && op1.z == op2.z; }
410 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
411 bool operator!=(
const float3 op1,
const float3 op2) {
return op1.x != op2.x || op1.y != op2.y || op1.z != op2.z; }
415 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
416 bool operator==(
const float4 op1,
const float4 op2) {
return op1.x == op2.x && op1.y == op2.y && op1.z == op2.z && op1.w == op2.w; }
420 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
421 bool operator!=(
const float4 op1,
const float4 op2) {
return op1.x != op2.x || op1.y != op2.y || op1.z != op2.z || op1.w != op2.w; }
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Out binary_cast(const In in)
Definition: types.h:288