Skip to content

Commit e2c57cd

Browse files
author
Henry Linjamäki
committed
Refactor may-have-IGBAs -> has-no-IGBAs
1 parent 8abba56 commit e2c57cd

8 files changed

Lines changed: 35 additions & 37 deletions

File tree

llvm_passes/HipIGBADetector.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@
1010
// buffer accesses (IGBA). The outcome of the analysis is stored in a magic
1111
// variable for the chipStar runtime:
1212
//
13-
// uint8_t __chip_module_may_have_IGBAs = <result>;
13+
// uint8_t __chip_module_has_no_IGBAs = <result>;
1414
//
15-
// Where the result is one if the are potential IGBAs and otherwise zero.
15+
// Where the result is one if the are no potential IGBAs and otherwise it is
16+
// zero.
1617
//
17-
// If there would be an IGPA in the module, there has to to be a load instruction
18-
// with a pointer operand which is either loaded from memory or crafted from an
19-
// integer (which OTOH is loaded from somewhere else). The analysis is very
20-
// simple and naive: we look for pointer load and inttoptr instructions in the
21-
// whole module. If we see any, we conclude there are potential IGBAs. Downsides
22-
// of this are that
18+
// If there would be an IGPA in the module, there has to to be a load
19+
// instruction with a pointer operand which is either loaded from memory or
20+
// crafted from an integer (which OTOH is loaded from somewhere else). The
21+
// analysis is very simple and naive: we look for pointer load and inttoptr
22+
// instructions in the whole module. If we see any, we conclude there are
23+
// potential IGBAs. Downsides of this are that
2324
//
24-
// * may-have-IGBAs flag is raised even tough only one kernel has IGBAs an
25+
// * may-have-IGBAs is concluded even tough only one kernel has IGBAs an
2526
// others don't
2627
//
27-
// * unoptimized modules (-O0) will likely raise may-have-IGBAs flag.
28+
// * unoptimized modules (-O0) will likely likely result in may-have-IGBAs
29+
// * conclusion
2830
//
2931
// The motivation for this analysis is to reduce clSetKernelExecInfo() calls in
3032
// the OpenCL backend.
@@ -58,15 +60,15 @@ static bool hasPotentialIGBAs(Module &M) {
5860
}
5961

6062
static bool detectIGBAs(Module &M) {
61-
constexpr auto *MagicVarName = "__chip_module_may_have_IGBAs";
63+
constexpr auto *MagicVarName = "__chip_module_has_no_IGBAs";
6264

6365
if (M.getGlobalVariable(MagicVarName))
6466
return false; // Bail out: the module has already been processed.
6567

6668
bool Result = hasPotentialIGBAs(M);
6769
LLVM_DEBUG(dbgs() << "Has IGBAs: " << Result << "\n");
6870

69-
auto *Init = ConstantInt::get(IntegerType::get(M.getContext(), 8), Result);
71+
auto *Init = ConstantInt::get(IntegerType::get(M.getContext(), 8), !Result);
7072
(void)new GlobalVariable(
7173
M, Init->getType(), true,
7274
// Mark the GV as external for keeping it alive at least until the

src/backend/OpenCL/CHIPBackendOpenCL.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,9 @@ annotateIndirectPointers(const CHIPContextOpenCL &Ctx,
235235
// If we have determined that the module does not have indirect
236236
// global memory accesses (IGBAs; see HipIGBADetectorPass), we may
237237
// skip the annotation.
238-
if (!ModInfo.MayHaveIGBAs)
238+
if (ModInfo.HasNoIGBAs)
239239
return nullptr;
240240

241-
242241
std::unique_ptr<std::vector<std::shared_ptr<void>>> AllocKeepAlives;
243242
std::vector<void *> AnnotationList;
244243
LOCK(Ctx.ContextMtx); // CHIPContextOpenCL::MemManager_

src/common.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ using SPVFunctionInfoMap = std::map<std::string, std::shared_ptr<SPVFuncInfo>>;
5757
struct SPVModuleInfo {
5858
SPVFunctionInfoMap FuncInfoMap;
5959

60-
/// Set to true if the module may have indirect global buffer
61-
/// accesses (IGBA) in any kernel.
62-
bool MayHaveIGBAs = true;
60+
/// Set to true if the module is known not to have indirect global
61+
/// buffer accesses (IGBA) in any kernel.
62+
bool HasNoIGBAs = false;
6363
};
6464

6565
bool filterSPIRV(const char *Bytes, size_t NumBytes, std::string &Dst);

src/spirv.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,11 @@ class SPIRVmodule {
516516
std::map<std::string_view, std::vector<std::pair<uint16_t, uint16_t>>>
517517
SpilledArgAnnotations_;
518518

519-
// This flag indicates if the module may have indirect global buffer
520-
// accesses (IGBA) in any kernel. This is told by a magic variable
521-
// created by HipIGBADetectorPass. Defaults to true in case the
522-
// variable is not found.
523-
bool MayHaveIGBAs_ = true;
519+
// This flag indicates if the module is known not to have indirect
520+
// global buffer accesses (IGBA) in any kernel. This is told by a
521+
// magic variable created by HipIGBADetectorPass. Defaults to false
522+
// in case the variable is not found.
523+
bool HasNoIGBAs_ = false;
524524

525525
bool MemModelCL_;
526526
bool KernelCapab_;
@@ -587,7 +587,7 @@ class SPIRVmodule {
587587
}
588588
KernelInfoMap_.clear();
589589

590-
ModuleInfo.MayHaveIGBAs = MayHaveIGBAs_;
590+
ModuleInfo.HasNoIGBAs = HasNoIGBAs_;
591591

592592
return true;
593593
}
@@ -733,11 +733,11 @@ class SPIRVmodule {
733733
}
734734

735735
// A magic variable created by HipIGBADetector.cpp.
736-
if (Name == "__chip_module_may_have_IGBAs") {
736+
if (Name == "__chip_module_has_no_IGBAs") {
737737
// Get initializer operand.
738738
auto *Init = getInstruction(Inst->getWord(4));
739739
// Init is known to be 8-bit unsigned constant.
740-
MayHaveIGBAs_ = Init->getWord(3);
740+
HasNoIGBAs_ = Init->getWord(3);
741741
}
742742
}
743743

tests/runtime/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,6 @@ target_compile_definitions(TestBitInsert
102102

103103
add_hip_runtime_test(TestBallot.hip)
104104

105-
add_hip_runtime_test(TestPositiveIGBADetection1.hip)
106-
add_hip_runtime_test(TestPositiveIGBADetection2.hip)
107-
add_hip_runtime_test(TestNegativeIGBADetection.hip)
105+
add_hip_runtime_test(TestNegativeHasNoIGBAs1.hip)
106+
add_hip_runtime_test(TestNegativeHasNoIGBAs2.hip)
107+
add_hip_runtime_test(TestPositiveHasNoIGBAs.hip)

tests/runtime/TestPositiveIGBADetection1.hip renamed to tests/runtime/TestNegativeHasNoIGBAs1.hip

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ __global__ void k(SomeStruct Args) { *Args.Ptr = 123; }
1919
int main() {
2020
auto *ChipKernel = Backend->getActiveDevice()->findKernel(
2121
HostPtr(reinterpret_cast<const void *>(k)));
22-
if (ChipKernel->getModule()->getInfo().MayHaveIGBAs)
23-
return 0;
24-
return 1;
22+
// HasNoIGBAs should be false here.
23+
return ChipKernel->getModule()->getInfo().HasNoIGBAs;
2524
}

tests/runtime/TestPositiveIGBADetection2.hip renamed to tests/runtime/TestNegativeHasNoIGBAs2.hip

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ __global__ void k(uintptr_t Arg) {
1717
int main() {
1818
auto *ChipKernel = Backend->getActiveDevice()->findKernel(
1919
HostPtr(reinterpret_cast<const void *>(k)));
20-
if (ChipKernel->getModule()->getInfo().MayHaveIGBAs)
21-
return 0;
22-
return 1;
20+
// HasNoIGBAs should be false here.
21+
return ChipKernel->getModule()->getInfo().HasNoIGBAs;
2322
}

tests/runtime/TestNegativeIGBADetection.hip renamed to tests/runtime/TestPositiveHasNoIGBAs.hip

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ __global__ void k(int *Out) { *Out = 123; }
1515
int main() {
1616
auto *ChipKernel = Backend->getActiveDevice()->findKernel(
1717
HostPtr(reinterpret_cast<const void *>(k)));
18-
if (!ChipKernel->getModule()->getInfo().MayHaveIGBAs)
19-
return 0;
20-
return 1;
18+
// HasNoIGBAs should be true here.
19+
return !ChipKernel->getModule()->getInfo().HasNoIGBAs;
2120
}

0 commit comments

Comments
 (0)