|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of libcu++, the C++ Standard Library for your entire system, |
| 4 | +// under the Apache License v2.0 with LLVM Exceptions. |
| 5 | +// See https://llvm.org/LICENSE.txt for license information. |
| 6 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +// UNSUPPORTED: pre-sm-70 |
| 11 | +// UNSUPPORTED: !nvcc |
| 12 | +// UNSUPPORTED: nvrtc |
| 13 | +// UNSUPPORTED: c++98, c++03 |
| 14 | + |
| 15 | +#include "utils.h" |
| 16 | + |
| 17 | +__device__ __host__ __noinline__ |
| 18 | +void test_access_property_interleave() { |
| 19 | + const uint64_t INTERLEAVE_NORMAL = uint64_t{0x10F0000000000000}; |
| 20 | + const uint64_t INTERLEAVE_NORMAL_DEMOTE = uint64_t{0x16F0000000000000}; |
| 21 | + const uint64_t INTERLEAVE_PERSISTING = uint64_t{0x14F0000000000000}; |
| 22 | + const uint64_t INTERLEAVE_STREAMING = uint64_t{0x12F0000000000000}; |
| 23 | + cuda::access_property ap(cuda::access_property::persisting{}); |
| 24 | + cuda::access_property ap2; |
| 25 | + |
| 26 | + assert(INTERLEAVE_PERSISTING == static_cast<uint64_t>(ap)); |
| 27 | + assert(static_cast<uint64_t>(ap2) == INTERLEAVE_NORMAL); |
| 28 | + |
| 29 | + ap = cuda::access_property(cuda::access_property::normal()); |
| 30 | + assert(static_cast<uint64_t>(ap) == INTERLEAVE_NORMAL_DEMOTE); |
| 31 | + |
| 32 | + ap = cuda::access_property(cuda::access_property::streaming()); |
| 33 | + assert(static_cast<uint64_t>(ap) == INTERLEAVE_STREAMING); |
| 34 | + |
| 35 | + ap = cuda::access_property(cuda::access_property::normal(), 2.0f); |
| 36 | + assert(static_cast<uint64_t>(ap) == INTERLEAVE_NORMAL_DEMOTE); |
| 37 | +} |
| 38 | + |
| 39 | +__device__ __host__ __noinline__ |
| 40 | +void test_access_property_block() { |
| 41 | + //assuming ptr address is 0; |
| 42 | + const size_t TOTAL_BYTES = 0xFFFFFFFF; |
| 43 | + const size_t HIT_BYTES = 0xFFFFFFFF; |
| 44 | + const size_t BLOCK_0ADDR_PERSISTHIT_STREAMISS_MAXBYTES = size_t{0x1DD00FE000000000}; |
| 45 | + const uint64_t INTERLEAVE_NORMAL = uint64_t{0x10F0000000000000}; |
| 46 | + |
| 47 | + cuda::access_property ap(0x0, HIT_BYTES, TOTAL_BYTES, cuda::access_property::persisting{}, cuda::access_property::streaming{}); |
| 48 | + assert(static_cast<uint64_t>(ap) == BLOCK_0ADDR_PERSISTHIT_STREAMISS_MAXBYTES); |
| 49 | + |
| 50 | + ap = cuda::access_property(0x0, 0xFFFFFFFF, 0xFFFFFFFFF, cuda::access_property::persisting{}, cuda::access_property::streaming{}); |
| 51 | + assert(static_cast<uint64_t>(ap) == INTERLEAVE_NORMAL); |
| 52 | + |
| 53 | + ap = cuda::access_property(0x0, 0xFFFFFFFFF, 0xFFFFFFFF, cuda::access_property::persisting{}, cuda::access_property::streaming{}); |
| 54 | + assert(static_cast<uint64_t>(ap) == INTERLEAVE_NORMAL); |
| 55 | + |
| 56 | + ap = cuda::access_property(0x0, 0, 0, cuda::access_property::persisting{}, cuda::access_property::streaming{}); |
| 57 | + assert(static_cast<uint64_t>(ap) == INTERLEAVE_NORMAL); |
| 58 | + |
| 59 | + for (size_t ptr = 1; ptr < size_t{0xFFFFFFFF}; ptr <<= 1) { |
| 60 | + for (size_t hit = 1; hit < size_t{0xFFFFFFFF}; hit <<= 1) { |
| 61 | + ap = cuda::access_property((void*)ptr, hit, hit, cuda::access_property::persisting{}, cuda::access_property::streaming{}); |
| 62 | + DPRINTF("Block encoding PTR:%p, hit:%p, block encoding:%p\n", ptr, hit, static_cast<uint64_t>(ap)); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +template<typename T> |
| 68 | +__host__ __device__ __noinline__ void test_global_implicit_property(T ap, cudaAccessProperty cp) { |
| 69 | + // Test implicit conversions |
| 70 | + cudaAccessProperty v = ap; |
| 71 | + assert(cp == v); |
| 72 | + |
| 73 | + // Test default, copy constructor, and copy-assignent |
| 74 | + cuda::access_property o(ap); |
| 75 | + cuda::access_property d; |
| 76 | + d = ap; |
| 77 | + |
| 78 | + // Test explicit conversion to i64 |
| 79 | + std::uint64_t x = (std::uint64_t)o; |
| 80 | + std::uint64_t y = (std::uint64_t)d; |
| 81 | + assert(x == y); |
| 82 | +} |
| 83 | + |
| 84 | +__host__ __device__ __noinline__ void test_global() { |
| 85 | + cuda::access_property o(cuda::access_property::global{}); |
| 86 | + std::uint64_t x = (std::uint64_t)o; |
| 87 | + unused(x); |
| 88 | +} |
| 89 | + |
| 90 | +__host__ __device__ __noinline__ void test_shared() { |
| 91 | + (void)cuda::access_property::shared{}; |
| 92 | +} |
| 93 | + |
| 94 | +static_assert(sizeof(cuda::access_property::shared) == 1, ""); |
| 95 | +static_assert(sizeof(cuda::access_property::global) == 1, ""); |
| 96 | +static_assert(sizeof(cuda::access_property::persisting) == 1, ""); |
| 97 | +static_assert(sizeof(cuda::access_property::normal) == 1, ""); |
| 98 | +static_assert(sizeof(cuda::access_property::streaming) == 1, ""); |
| 99 | +static_assert(sizeof(cuda::access_property) == 8, ""); |
| 100 | + |
| 101 | +static_assert(alignof(cuda::access_property::shared) == 1, ""); |
| 102 | +static_assert(alignof(cuda::access_property::global) == 1, ""); |
| 103 | +static_assert(alignof(cuda::access_property::persisting) == 1, ""); |
| 104 | +static_assert(alignof(cuda::access_property::normal) == 1, ""); |
| 105 | +static_assert(alignof(cuda::access_property::streaming) == 1, ""); |
| 106 | +static_assert(alignof(cuda::access_property) == 8, ""); |
| 107 | + |
| 108 | +int main(int argc, char ** argv) |
| 109 | +{ |
| 110 | + test_access_property_interleave(); |
| 111 | + test_access_property_block(); |
| 112 | + |
| 113 | + test_global_implicit_property(cuda::access_property::normal{}, cudaAccessProperty::cudaAccessPropertyNormal); |
| 114 | + test_global_implicit_property(cuda::access_property::streaming{}, cudaAccessProperty::cudaAccessPropertyStreaming); |
| 115 | + test_global_implicit_property(cuda::access_property::persisting{}, cudaAccessProperty::cudaAccessPropertyPersisting); |
| 116 | + |
| 117 | + test_global(); |
| 118 | + test_shared(); |
| 119 | + |
| 120 | + return 0; |
| 121 | +} |
0 commit comments