config.hpp 6.97 KB
Newer Older
Chao Liu's avatar
Chao Liu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*******************************************************************************
 * MIT License
 *
 * Copyright (c) 2018 - present Advanced Micro Devices, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 *******************************************************************************/
25
26
27
#ifndef CK_CONFIG_AMD_HPP
#define CK_CONFIG_AMD_HPP

JD's avatar
JD committed
28
#ifndef CK_DONT_USE_HIP_RUNTIME_HEADERS
29
30
#include "hip/hip_runtime.h"
#include "hip/hip_fp16.h"
Chao Liu's avatar
Chao Liu committed
31
#endif
32

33
34
35
// constant address space for kernel parameter
// https://llvm.org/docs/AMDGPUUsage.html#address-spaces
#define CK_CONSTANT_ADDRESS_SPACE __attribute__((address_space(4)))
Chao Liu's avatar
Chao Liu committed
36
37

// launch bounds
zjing14's avatar
zjing14 committed
38
#define CK_USE_LAUNCH_BOUNDS 1
Chao Liu's avatar
Chao Liu committed
39
40
41

#ifdef CK_USE_LAUNCH_BOUNDS
#define CK_MAX_THREAD_PER_BLOCK 256
Chao Liu's avatar
Chao Liu committed
42
#define CK_MIN_BLOCK_PER_CU 2
Chao Liu's avatar
Chao Liu committed
43
44
#endif

45
46
47
48
49
50
51
52
// check GPU target
#ifdef __HIP_DEVICE_COMPILE__
#if !(defined(__gfx803__) || defined(__gfx900__) || defined(__gfx906__) || defined(__gfx908__) || \
      defined(__gfx90a__) || defined(__gfx1030__))
#error Not supported target
#endif
#endif

Chao Liu's avatar
Chao Liu committed
53
// buffer resource
54
55
56
57
#ifndef __HIP_DEVICE_COMPILE__ // for host code
#define CK_BUFFER_RESOURCE_3RD_DWORD -1
#elif defined(__gfx803__) || defined(__gfx900__) || defined(__gfx906__) || defined(__gfx908__) || \
    defined(__gfx90a__) // for GPU code
Chao Liu's avatar
Chao Liu committed
58
#define CK_BUFFER_RESOURCE_3RD_DWORD 0x00020000
59
#elif defined(__gfx1030__) // for GPU code
Chao Liu's avatar
Chao Liu committed
60
61
62
#define CK_BUFFER_RESOURCE_3RD_DWORD 0x31014000
#endif

63
// FMA instruction
64
65
#ifndef __HIP_DEVICE_COMPILE__                   // for host code, define nothing
#elif defined(__gfx803__) || defined(__gfx900__) // for GPU code
66
#define CK_USE_AMD_V_MAC_F32
67
68
#elif defined(__gfx906__) || defined(__gfx908__) || defined(__gfx90a__) || \
    defined(__gfx1030__) // for GPU code
69
70
71
72
73
#define CK_USE_AMD_V_FMAC_F32
#define CK_USE_AMD_V_DOT2_F32_F16
#define CK_USE_AMD_V_DOT4_I32_I8
#endif

74
75
76
77
78
// MFMA instruction
#ifndef __HIP_DEVICE_COMPILE__ // for host code
#define CK_USE_AMD_MFMA
#elif defined(__gfx908__) || defined(__gfx90a__) // for GPU code
#define CK_USE_AMD_MFMA
79
80
#endif

81
82
#if defined(__gfx90a__)
#define CK_USE_AMD_MFMA_BF16_1K_OP
Chao Liu's avatar
Chao Liu committed
83
84
#endif

85
// buffer load
Jianfeng Yan's avatar
Jianfeng Yan committed
86
#define CK_USE_AMD_BUFFER_LOAD 1
87

88
// buffer store
Jianfeng Yan's avatar
Jianfeng Yan committed
89
90
#define CK_USE_AMD_BUFFER_STORE 1

91
92
// buffer atomic add: integer
#define CK_USE_AMD_BUFFER_ATOMIC_ADD_INTEGER 1
93

94
95
96
97
98
99
100
// buffer atomic add: floating point
#ifndef __HIP_DEVICE_COMPILE__ // for host code
#define CK_USE_AMD_BUFFER_ATOMIC_ADD_FLOAT 1
#elif defined(__gfx908__) || defined(__gfx90a__) // for GPU code
#define CK_USE_AMD_BUFFER_ATOMIC_ADD_FLOAT 1
#else // for GPU code
#define CK_USE_AMD_BUFFER_ATOMIC_ADD_FLOAT 0
101
102
#endif

rocking5566's avatar
rocking5566 committed
103
104
105
106
107
108
#if defined(__gfx90a__) // for GPU code
#define CK_USE_AMD_BUFFER_ATOMIC_MAX_FLOAT64 1
#else
#define CK_USE_AMD_BUFFER_ATOMIC_MAX_FLOAT64 0
#endif

109
110
111
112
113
114
// inline asm
#define CK_USE_AMD_INLINE_ASM 1

// inner product (DLOP)
#define CK_USE_AMD_INNER_PRODUCT_INLINE_ASM 1

Chao Liu's avatar
Chao Liu committed
115
// block synchronization only s_wait lgkmcnt(0), not vmcnt(0)
116
#define CK_EXPERIMENTAL_BLOCK_SYNC_LDS_WITHOUT_SYNC_VMEM 1
Chao Liu's avatar
Chao Liu committed
117

118
119
// experimental feature: multi index implemented as array
#define CK_EXPERIMENTAL_USE_DYNAMICALLY_INDEXED_MULTI_INDEX 0
Chao Liu's avatar
Chao Liu committed
120

121
122
// experimental feature: static tensor descriptor
#define CK_EXPERIMENTAL_STATIC_TENSOR_DESCRIPTOR 0
Chao Liu's avatar
Chao Liu committed
123

rocking5566's avatar
rocking5566 committed
124
// experimental feature: buffer load/store/atomic-add/ OOB trick
125
126
#define CK_EXPERIMENTAL_USE_BUFFER_LOAD_OOB_CHECK_OFFSET_TRICK 0
#define CK_EXPERIMENTAL_USE_BUFFER_STORE_OOB_CHECK_OFFSET_TRICK 1
zjing14's avatar
zjing14 committed
127
#define CK_EXPERIMENTAL_USE_BUFFER_ATOMIC_ADD_OOB_CHECK_OFFSET_TRICK 1
rocking5566's avatar
rocking5566 committed
128
#define CK_EXPERIMENTAL_USE_BUFFER_ATOMIC_MAX_OOB_CHECK_OFFSET_TRICK 1
129

130
// experimental feature: in-regsiter sub-dword transpose
131
#define CK_EXPERIMENTAL_USE_IN_REGISTER_SUB_DWORD_TRANSPOSE 1
Chao Liu's avatar
Chao Liu committed
132

133
// experimental feature: merge transformation use magic number division
134
#define CK_EXPERIMENTAL_MERGE_USE_MAGIC_DIVISION 1
135

136
137
// experimental feature: use __builtin_memcpy instead of pointer cast to access a vector from
// pointer of scalar
138
139
#define CK_EXPERIMENTAL_USE_MEMCPY_FOR_VECTOR_ACCESS 0

140
// experimental feature: use __builtin_memcpy instead of union to do bit_cast
141
#define CK_EXPERIMENTAL_USE_MEMCPY_FOR_BIT_CAST 1
142

143
144
145
146
// experimental feature: optimize for inter-wave scheduling policy
#define CK_EXPERIMENTAL_INTER_WAVE_SCHEDULING 0
#define CK_EXPERIMENTAL_INTER_WAVE_SCHEDULING_MAC_CLUSTERS 1

Chao Liu's avatar
Chao Liu committed
147
148
149
150
// hack: have underlying assumption that need to be satsified, otherwise it's a bug
// hack for forcing register to keep idx_diff_low_const in SGPR. idx_diff_low_const must be
// thread-invariant, otherwise it's a bug
// TODO: separate index calculation into "compile-time", "global", "block", "wave", "thread"
Chao Liu's avatar
rename  
Chao Liu committed
151
#define CK_HACK_MERGE_CALCULATE_IDX_DIFF_LOW_CONST_USE_AMD_GCN_READ_FIRST_LANE 0
Chao Liu's avatar
Chao Liu committed
152

153
// workaround: compiler crash when compiling recursive lambda
Chao Liu's avatar
Chao Liu committed
154
#define CK_WORKAROUND_SWDEV_275126 1
155

156
// workaround: compiler crash when using buffer load/store for i8
157
158
#define CK_WORKAROUND_SWDEV_XXXXXX_INT8_BUFFER_LOAD_STORE_ISSUE 1

159
// workaround: compiler gnerating inefficient ds_write instructions
160
#define CK_WORKAROUND_SWDEV_XXXXXX_INT8_DS_WRITE_ISSUE 1
Chao Liu's avatar
Chao Liu committed
161

162
// workaround: verifaction failure, due to compiler regression, for conv bwd-data fp16 using some
163
164
165
// tuning parameter
#define CK_WORKAROUND_SWDEV_325164 1

166
167
168
169
// workaround for verification failure ConvNd forward
// https://github.com/ROCmSoftwarePlatform/composable_kernel/issues/135
#define CK_WORKAROUND_GITHUB_135 1

170
171
namespace ck {

172
enum struct InMemoryDataOperationEnum
Chao Liu's avatar
Chao Liu committed
173
{
Chao Liu's avatar
Chao Liu committed
174
    Set,
175
    AtomicAdd,
rocking5566's avatar
rocking5566 committed
176
    AtomicMax,
177
178
179
    Add
};

rocking5566's avatar
rocking5566 committed
180
181
182
183
184
185
186
187
188
189
190
191
192
template <InMemoryDataOperationEnum... Is>
struct InMemoryDataOperationEnumSequence
{
    static constexpr int mSize = sizeof...(Is);

    __host__ __device__ static constexpr InMemoryDataOperationEnum At(int I)
    {
        // the last dummy element is to prevent compiler complain about empty array, when mSize = 0
        const InMemoryDataOperationEnum mData[mSize + 1] = {Is..., InMemoryDataOperationEnum::Set};
        return mData[I];
    }
};

193
194
// TODO: no longer needed, remove this
enum struct ActivTypeEnum
195
{
Chao Liu's avatar
Chao Liu committed
196
    None,
197
198
    LeakyRelu,
    Sigmoid
199
200
};

Chao Liu's avatar
Chao Liu committed
201
// index type
Jianfeng Yan's avatar
Jianfeng Yan committed
202
203
using index_t      = int32_t;
using long_index_t = int64_t;
204
205
206

} // namespace ck
#endif