amd_address_space.hpp 1.12 KB
Newer Older
Chao Liu's avatar
Chao Liu committed
1
#pragma once
Chao Liu's avatar
tidy  
Chao Liu committed
2

Chao Liu's avatar
Chao Liu committed
3
#include "ck/ck.hpp"
Chao Liu's avatar
Chao Liu committed
4
#include "c_style_pointer_cast.hpp"
Chao Liu's avatar
tidy  
Chao Liu committed
5

Chao Liu's avatar
Chao Liu committed
6
7
8
// Address Space for AMDGCN
// https://llvm.org/docs/AMDGPUUsage.html#address-space

Chao Liu's avatar
tidy  
Chao Liu committed
9
10
namespace ck {

11
enum struct AddressSpaceEnum
Chao Liu's avatar
tidy  
Chao Liu committed
12
13
14
15
16
17
18
19
20
{
    Generic,
    Global,
    Lds,
    Sgpr,
    Vgpr,
};

template <typename T>
21
__device__ T* cast_pointer_to_generic_address_space(T CK_CONSTANT_ADDRESS_SPACE* p)
Chao Liu's avatar
tidy  
Chao Liu committed
22
{
Chao Liu's avatar
Chao Liu committed
23
    // cast a pointer in "Constant" address space (4) to "Generic" address space (0)
Chao Liu's avatar
Chao Liu committed
24
    // only c-style pointer cast seems be able to be compiled
Chao Liu's avatar
Chao Liu committed
25
#pragma clang diagnostic push
Chao Liu's avatar
Chao Liu committed
26
#pragma clang diagnostic ignored "-Wold-style-cast"
Chao Liu's avatar
Chao Liu committed
27
28
    return (T*)p; // NOLINT(old-style-cast)
#pragma clang diagnostic pop
Chao Liu's avatar
tidy  
Chao Liu committed
29
30
}

Chao Liu's avatar
tidy  
Chao Liu committed
31
template <typename T>
32
__host__ __device__ T CK_CONSTANT_ADDRESS_SPACE* cast_pointer_to_constant_address_space(T* p)
Chao Liu's avatar
tidy  
Chao Liu committed
33
{
Chao Liu's avatar
Chao Liu committed
34
    // cast a pointer in "Generic" address space (0) to "Constant" address space (4)
Chao Liu's avatar
Chao Liu committed
35
    // only c-style pointer cast seems be able to be compiled
Chao Liu's avatar
Chao Liu committed
36
#pragma clang diagnostic push
Chao Liu's avatar
Chao Liu committed
37
#pragma clang diagnostic ignored "-Wold-style-cast"
38
    return (T CK_CONSTANT_ADDRESS_SPACE*)p; // NOLINT(old-style-cast)
Chao Liu's avatar
Chao Liu committed
39
#pragma clang diagnostic pop
Chao Liu's avatar
tidy  
Chao Liu committed
40
41
}

Chao Liu's avatar
tidy  
Chao Liu committed
42
} // namespace ck