1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| namespace testnm {
template<typename T> __device__ void general_template(void **addr) { __attribute__((scoped_local)) int originA, originB, originC; addr[0] = &originA; addr[1] = &originA; addr[2] = &originA; printf("originA:%d %p\\n", originA, &originA); printf("originB:%d %p\\n", originB, &originB); printf("originC:%d %p\\n", originC, &originC); }
template<typename T> __device__ void general_template(T n, void **addr) { __attribute__((scoped_local)) int originA; printf("templateArgA:%d %p\\n", originA, &originA); }
template<> __device__ void general_template<double>(void **addr) { __attribute__((scoped_local)) int originA; addr[0] = &originA; printf("doubleX:%d %p\\n", originA, &originA); }
template<typename T1, typename T2> __device__ void general_template(void **addr) { __attribute__((scoped_local)) int originA; addr[0] = &originA; printf("doubleTemplateA:%d %p\\n", originA, &originA); }
template<typename T> __device__ void run_test_another(void **addr) { __attribute__((scoped_local)) int originA; addr[0] = &originA; printf("another A:%d %p\\n", originA, &originA); } }
namespace another_nm { template<typename T> __device__ void general_template(void **addr) { __attribute__((scoped_local)) int originA, originB, originC, originD; addr[0] = &originA; addr[1] = &originB; addr[2] = &originC; addr[3] = &originD; printf("another nm:%p\\n", originA, &originA); printf("another nm:%d %p\\n", originB, &originB); printf("another nm:%d %p\\n", originC, &originC); printf("another nm:%d %p\\n", originD, &originD); } }
__device__ int check_addr_eq(void **a, void **b, int size) { int count = 0; for (size_t i = 0; i < size; i++) { if (a[i] != b[i]) { count++; } } return count; }
__device__ int check_addr_ne(void **a, void **b, int size) { int count = 0; for (size_t i = 0; i < size; i++) { if (a[i] == b[i]) { count++; } } return count; }
__device__ void check_optimized(int *errnum, void **baseP) { void **updateP = (void**)malloc(4 * sizeof(void *)); testnm::general_template<int>(baseP); testnm::general_template<float>(updateP); errnum += check_addr_eq(baseP, updateP, 3); testnm::general_template<unsigned int>(updateP); errnum += check_addr_eq(baseP, updateP, 3); testnm::general_template<char>(updateP); errnum += check_addr_eq(baseP, updateP, 3); testnm::general_template<int>(updateP); errnum += check_addr_eq(baseP, updateP, 3); testnm::general_template<double>(updateP); errnum += check_addr_ne(baseP, updateP, 1); testnm::general_template<int>(4, updateP); errnum += check_addr_ne(baseP, updateP, 1); testnm::general_template<int, float>(updateP); errnum += check_addr_ne(baseP, updateP, 1); testnm::run_test_another<char>(updateP); errnum += check_addr_ne(baseP, updateP, 1); another_nm::general_template<int>(updateP); errnum += check_addr_ne(baseP, updateP, 4); }
template<typename T> __device__ void test_template_local(void **addr) { __scoped_local__ T originA; printf("test_template_local %p\\n", &originA); }
template<typename T> struct RS { T a; };
template<typename T> inline __attribute__((always_inline))__device__ void test_template_structure(void **addr) { __scoped_local__ RS<T> originA; printf("test_template_structure %p\\n", &originA); }
__device__ void check_should_not_opt(int *errnum, void **baseP) { test_template_local<int>(baseP); test_template_local<float>(baseP); test_template_structure<int>(baseP); test_template_structure<float>(baseP); } __global__ void test_scoped_local() { if(threadIdx != 0) return; void **baseP = (void**)malloc(4 * sizeof(void *)); int errnum = 0; check_optimized(&errnum, baseP); check_should_not_opt(&errnum, baseP); }
|