Skip to content

Commit cdf6c21

Browse files
authored
Merge pull request #5 from AMDResearch/rocm-4.0.1
ROCm 4.0.1 updates
2 parents 9c31e07 + 1138134 commit cdf6c21

6 files changed

Lines changed: 108 additions & 5 deletions

File tree

DAGEE-lib/include/dagee/ATMIgpuExecutor.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace dagee {
1111

12-
using ATMIgpuKernelInfo = atmi_kernel_t;
12+
struct ATMIgpuKernelInfo {
13+
atmi_kernel_t mKern;
14+
};
1315

1416
// TODO(amber): Store mKernArgOffsets as part of ATMIgpuKernelInfo
1517
template <typename AllocFactory>
@@ -65,7 +67,7 @@ struct GpuKernelRegAtmiPolicy {
6567
protected:
6668
using KernPtrLookup = KernelPtrToNameLookup<AllocFactory>;
6769

68-
using KernelInfoMap = typename AllocFactory::template HashMap<GenericFuncPtr, KernelInfo>;
70+
using KernelInfoMap = typename AllocFactory::template HashMap<GenericFuncPtr, atmi_kernel_t>;
6971

7072
KernPtrLookup mKernPtrLookup;
7173

@@ -119,7 +121,7 @@ struct GpuKernelRegAtmiPolicy {
119121
auto kiter = mGpuKernels.find(fptr);
120122

121123
if (kiter != mGpuKernels.cend()) {
122-
return kiter->second;
124+
return KernelInfo{ kiter->second };
123125

124126
} else {
125127
const auto& name = mKernPtrLookup.name(fptr);
@@ -132,7 +134,7 @@ struct GpuKernelRegAtmiPolicy {
132134

133135
mGpuKernels.insert(kiter, std::make_pair(fptr, kernel));
134136

135-
return kernel;
137+
return KernelInfo{ kernel };
136138
}
137139
}
138140
};
@@ -163,13 +165,18 @@ struct GpuKernelLaunchAtmiPolicy {
163165
return lp;
164166
}
165167

166-
static ATMIkernelHandle kernelHandle(const TaskInstance& ti) { return ti.mKernInfo; }
168+
static ATMIkernelHandle kernelHandle(const TaskInstance& ti) { return ti.mKernInfo.mKern; }
167169

168170
template <typename... Args>
169171
static TaskInstance makeTask(const dim3& blocks, const dim3& threadsPerBlock,
170172
const KernelInfo& kinfo, Args&&... args) {
171173
return TaskInstance(blocks, threadsPerBlock, kinfo, std::forward<Args>(args)...);
172174
}
175+
176+
template <typename... Args>
177+
static TaskInstance makeTask(const dim3& threads, const KernelInfo& kinfo, Args&&... args) {
178+
return makeTask(1, threads, kinfo, std::forward<Args>(args)...);
179+
}
173180
};
174181

175182
using GpuExecutorAtmi =

cmakeUtils/addATMI.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ if(ATMI_BUILD_FROM_SRC)
1818
set(LLVM_DIR ${AMD_LLVM})
1919
# set(DEVICE_LIB_DIR ${ROCM_DEVICE_LIBS})
2020
set(ATMI_DEVICE_RUNTIME ON)
21+
# pass through ROCm/HSA root dir to be consistent with ATMI
22+
set(ROCM_DIR ${ROCM_ROOT})
23+
set(ENV{GFXLIST} "${GFX_VER}")
2124
# invoke src/CMakeLists.txt
2225
add_subdirectory(${ATMI_SRC}/src ${ATMI_ROOT})
2326
# set variables for apps to use ATMI

cppUtils/include/cpputils/BitUtil.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ struct BitUtil {
6868
return res;
6969
}
7070

71+
static W getBitsByMask(const W& word, const W& mask) noexcept {
72+
W res = 0;
73+
unsigned idx = 0;
74+
for (auto i = 0; i < NUM_BITS; ++i) {
75+
if (getBit(mask, i)) {
76+
W temp = getBit(word, i);
77+
res = res | (temp << idx);
78+
++idx;
79+
}
80+
}
81+
return res;
82+
}
83+
7184
static W setBitRange(const W& word, size_t lo, size_t hi) noexcept {
7285
checkBitRange(lo, hi);
7386
return (word | genMask(lo, hi));
@@ -88,6 +101,17 @@ struct BitUtil {
88101
return ret;
89102
}
90103

104+
static W setBitsByMask(const W& word, const W& mask) noexcept {
105+
W ret = word;
106+
107+
for (auto i = 0; i < NUM_BITS; ++i) {
108+
if (getBit(mask, i)) {
109+
ret = setBit(ret, i);
110+
}
111+
}
112+
return ret;
113+
}
114+
91115
static W clearBitRange(const W& word, size_t lo, size_t hi) noexcept {
92116
checkBitRange(lo, hi);
93117
return word & ~genMask(lo, hi);
@@ -154,6 +178,26 @@ struct BitUtil {
154178
return ret;
155179
}
156180

181+
static W removeBitsByMask(const W& word, const W& mask) noexcept {
182+
W res = word;
183+
size_t shiftAmt = 0;
184+
for (auto i = 0; i < NUM_BITS; ++i) {
185+
if (getBit(mask, i)) {
186+
res = removeBit(res, i);
187+
/*
188+
* since bitIndices are sorted, removing a lower order bit changes the
189+
* positions of higher order bits, so higher bitIndices are off by 1
190+
* So, we left shift by 1 to make higher bitIndices valid, but ++shiftAmt to
191+
* remember how many zeros we added on the right and remove them
192+
*/
193+
res <<= 1;
194+
++shiftAmt;
195+
}
196+
}
197+
res >>= shiftAmt; // remove the zeroes we added to adjust for higher bitIndices
198+
return res;
199+
}
200+
157201
/**
158202
* assumes that bitIndices are sorted low to high idx
159203
*/
@@ -197,6 +241,16 @@ struct BitUtil {
197241
return insertBitRange(word, idx, idx + 1);
198242
}
199243

244+
static W insertBitsByMask(const W& word, const W& mask) noexcept {
245+
W ret = word;
246+
for (auto i = 0; i < NUM_BITS; ++i) {
247+
if (getBit(mask, i)) {
248+
ret = insertBit(ret, i);
249+
}
250+
}
251+
return ret;
252+
}
253+
200254
// This does the opposite of removeBitsByInnerBits. It uses each element of innerBitIndices to
201255
// capture the right set of bits from word and shift them appropriately to insert bits at
202256
// the right locations.
@@ -253,6 +307,19 @@ struct BitUtil {
253307
}
254308
return ret;
255309
}
310+
311+
static W replaceBitsByMask(const W& word, const W& mask, const W& newVal) noexcept {
312+
W ret = word;
313+
W nval = newVal;
314+
315+
for (auto i = 0; i < NUM_BITS; ++i) {
316+
if (getBit(mask, i)) {
317+
ret = replaceBit(ret, i, getLSB(nval));
318+
nval >>= 1;
319+
}
320+
}
321+
return ret;
322+
}
256323
};
257324

258325
template <typename T>
@@ -306,6 +373,10 @@ class BitUtil<T*> {
306373
return toPtr(IntBitUtil::getBits(toInt(ptr), bitIndices));
307374
}
308375

376+
static P getBitsByMask(const P& ptr, Int mask) noexcept {
377+
return toPtr(IntBitUtil::getBitsByMask(toInt(ptr), mask));
378+
}
379+
309380
static P setBit(const P& ptr, size_t idx) noexcept {
310381
return toPtr(IntBitUtil::setBit(toInt(ptr), idx));
311382
}
@@ -319,6 +390,10 @@ class BitUtil<T*> {
319390
return toPtr(IntBitUtil::setBits(toInt(ptr), bitIndices));
320391
}
321392

393+
static P setBitsByMask(const P& ptr, Int mask) noexcept {
394+
return toPtr(IntBitUtil::setBits(toInt(ptr), mask));
395+
}
396+
322397
static P clearBit(const P& ptr, size_t idx) noexcept {
323398
return toPtr(IntBitUtil::clearBit(toInt(ptr), idx));
324399
}
@@ -345,6 +420,10 @@ class BitUtil<T*> {
345420
return toPtr(IntBitUtil::replaceBits(toInt(ptr), bitIndices, toInt(newVal)));
346421
}
347422

423+
static P replaceBitsByMask(const P& ptr, Int mask, const P& newVal) noexcept {
424+
return toPtr(IntBitUtil::replaceBitsByMask(toInt(ptr), mask, toInt(newVal)));
425+
}
426+
348427
static P removeBit(const P& ptr, size_t idx) noexcept {
349428
return toPtr(IntBitUtil::removeBit(toInt(ptr), idx));
350429
}
@@ -357,6 +436,10 @@ class BitUtil<T*> {
357436
static P removeBits(const P& ptr, const V& bitIndices) noexcept {
358437
return toPtr(IntBitUtil::removeBits(toInt(ptr), bitIndices));
359438
}
439+
440+
static P removeBitsByMask(const P& ptr, Int mask) noexcept {
441+
return toPtr(IntBitUtil::removeBitsByMask(toInt(ptr), mask));
442+
}
360443

361444
template <typename V>
362445
static P removeBitsByInnerBits(const P& ptr, const V& innerBitIndices) noexcept {
@@ -376,6 +459,10 @@ class BitUtil<T*> {
376459
return toPtr(IntBitUtil::insertBits(toInt(ptr), bitIndices));
377460
}
378461

462+
static P insertBitsByMask(const P& ptr, Int mask) noexcept {
463+
return toPtr(IntBitUtil::insertBitsByMask(toInt(ptr), mask));
464+
}
465+
379466
template <typename V>
380467
static P insertBitsByInnerBits(const P& ptr, const V& innerBitIndices) noexcept {
381468
return toPtr(IntBitUtil::insertBitsByInnerBits(toInt(ptr), innerBitIndices));

examples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ function(addDageeTarget EXE_NAME SRC_NAME)
44
add_executable(${EXE_NAME} ${SRC_NAME})
55
buildWithATMI(${EXE_NAME})
66
add_test(${EXE_NAME} ${EXE_NAME})
7+
# FIXME TODO(ashwin): disable SDMA because there seems to be a bug specifically
8+
# with device-to-host copies (for certain buffer sizes). Remove the below line
9+
# when the bug gets fixed.
10+
set_tests_properties(${EXE_NAME} PROPERTIES ENVIRONMENT HSA_ENABLE_SDMA=0)
711
endfunction()
812

913
addDageeTarget(kiteDagSimple kiteDagSimple.cpp)

examples/kiteDagMixed.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void checkOutput(const V& A) {
5757
std::cout << "OK. Output check passed" << std::endl;
5858
} else {
5959
std::cerr << "ERROR. Output check failed" << std::endl;
60+
std::abort();
6061
}
6162
}
6263

examples/kiteDagMixedNoAuto.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void checkOutput(const V& A) {
5757
std::cout << "OK. Output check passed" << std::endl;
5858
} else {
5959
std::cerr << "ERROR. Output check failed" << std::endl;
60+
std::abort();
6061
}
6162
}
6263

0 commit comments

Comments
 (0)