amd_address_space.hpp 1.12 KB
Newer Older
Chao Liu's avatar
tidy  
Chao Liu committed
1
2
3
4
#ifndef CK_AMD_ADDRESS_SPACE_HPP
#define CK_AMD_ADDRESS_SPACE_HPP

#include "config.hpp"
Chao Liu's avatar
Chao Liu committed
5
#include "c_style_pointer_cast.hpp"
Chao Liu's avatar
tidy  
Chao Liu committed
6

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

Chao Liu's avatar
tidy  
Chao Liu committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
namespace ck {

enum AddressSpaceEnum_t
{
    Generic,
    Global,
    Lds,
    Sgpr,
    Vgpr,
};

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

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

Chao Liu's avatar
tidy  
Chao Liu committed
43
44
} // namespace ck
#endif