nvccfeatures.h (4479B)
1 /* 2 Copyright 2010-2011, D. E. Shaw Research. 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are 7 met: 8 9 * Redistributions of source code must retain the above copyright 10 notice, this list of conditions, and the following disclaimer. 11 12 * Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions, and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 * Neither the name of D. E. Shaw Research nor the names of its 17 contributors may be used to endorse or promote products derived from 18 this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 #ifndef __r123_nvcc_features_dot_h__ 33 #define __r123_nvcc_features_dot_h__ 34 35 #if !defined(CUDART_VERSION) 36 #error "why are we in nvccfeatures.h if CUDART_VERSION is not defined" 37 #endif 38 39 #if CUDART_VERSION < 4010 40 #error "CUDA versions earlier than 4.1 produce incorrect results for some templated functions in namespaces. Random123 isunsupported. See comments in nvccfeatures.h" 41 // This test was added in Random123-1.08 (August, 2013) because we 42 // discovered that Ftype(maxTvalue<T>()) with Ftype=double and 43 // T=uint64_t in examples/uniform.hpp produces -1 for CUDA4.0 and 44 // earlier. We can't be sure this bug doesn't also affect invocations 45 // of other templated functions, e.g., essentially all of Random123. 46 // Thus, we no longer trust CUDA versions earlier than 4.1 even though 47 // we had previously tested and timed Random123 with CUDA 3.x and 4.0. 48 // If you feel lucky or desperate, you can change #error to #warning, but 49 // please take extra care to be sure that you are getting correct 50 // results. 51 #endif 52 53 // nvcc falls through to gcc or msvc. So first define 54 // a couple of things and then include either gccfeatures.h 55 // or msvcfeatures.h 56 57 //#ifdef __CUDA_ARCH__ allows Philox32 and Philox64 to be compiled 58 //for both device and host functions in CUDA by setting compiler flags 59 //for the device function 60 #ifdef __CUDA_ARCH__ 61 #ifndef R123_CUDA_DEVICE 62 #define R123_CUDA_DEVICE __device__ 63 #endif 64 65 #ifndef R123_USE_MULHILO64_CUDA_INTRIN 66 #define R123_USE_MULHILO64_CUDA_INTRIN 1 67 #endif 68 69 #ifndef R123_THROW 70 // No exceptions in CUDA, at least upto 4.0 71 #define R123_THROW(x) R123_ASSERT(0) 72 #endif 73 74 #ifndef R123_ASSERT 75 #define R123_ASSERT(x) if((x)) ; else asm("trap;") 76 #endif 77 78 #ifndef R123_BUILTIN_EXPECT 79 #define R123_BUILTIN_EXPECT(expr,likely) expr 80 #endif 81 82 #ifndef R123_USE_AES_NI 83 #define R123_USE_AES_NI 0 84 #endif 85 86 #ifndef R123_USE_SSE4_2 87 #define R123_USE_SSE4_2 0 88 #endif 89 90 #ifndef R123_USE_SSE4_1 91 #define R123_USE_SSE4_1 0 92 #endif 93 94 #ifndef R123_USE_SSE 95 #define R123_USE_SSE 0 96 #endif 97 98 #ifndef R123_USE_GNU_UINT128 99 #define R123_USE_GNU_UINT128 0 100 #endif 101 102 #ifndef R123_ULONG_LONG 103 // uint64_t, which is what we'd get without this, is 104 // not the same as unsigned long long 105 #define R123_ULONG_LONG unsigned long long 106 #endif 107 108 #else // ! __CUDA_ARCH__ 109 110 // If we're using nvcc, but not compiling for the CUDA architecture, 111 // then we must be compiling for the host. But host-compilation might 112 // use gcc, msvc, or xlc. This #else/#endif used to be higher up, 113 // mistakenly turning off all kinds of things the host that are really 114 // problematic only in device code. It's not clear that we need to do 115 // anything special for host-code that we wouldn't otherwise do in 116 // xlcfeatures, gccfeatures or msvcfeatures. But if we do, this is 117 // the place to do it. 118 119 #endif // __CUDA_ARCH__ 120 121 #if defined(__xlC__) || defined(__ibmxl__) 122 #include "xlcfeatures.h" 123 #elif defined(__GNUC__) 124 #include "gccfeatures.h" 125 #elif defined(_MSC_FULL_VER) 126 #include "msvcfeatures.h" 127 #endif 128 129 #endif