Skip to content

Commit ed78368

Browse files
Aditya Atluritqchen
authored andcommitted
added support for rocm gpu autodetect (#549)
* added support for rocm gpu autodetect * changed type casting from old style to static_cast * fixed code to generate gfx specific code object * fixed namespaces
1 parent 87c929f commit ed78368

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

HalideIR

src/codegen/llvm/codegen_amdgpu.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,21 @@ runtime::Module BuildAMDGPU(Array<LoweredFunc> funcs, std::string target) {
135135
CHECK(target.length(
136136
) >= 4 &&
137137
target.substr(0, 4) == "rocm");
138+
139+
TVMContext tvmCtx;
140+
tvmCtx.device_type = kROCM;
141+
tvmCtx.device_id = 0;
142+
TVMRetValue val;
143+
tvm::runtime::DeviceAPI::Get(tvmCtx)->GetAttr(tvmCtx, tvm::runtime::kExist, &val);
144+
if (val.operator int() == 1) {
145+
tvm::runtime::DeviceAPI::Get(tvmCtx)->GetAttr(tvmCtx, tvm::runtime::kComputeVersion, &val);
146+
} else {
147+
val = 803;
148+
}
149+
138150
llvm::TargetMachine* tm = \
139-
GetLLVMTargetMachine("-mtriple=amdgcn-amd-amdhsa-hcc -mcpu=gfx803" + \
140-
target.substr(4, target.length() - 4));
151+
GetLLVMTargetMachine("-mtriple=amdgcn-amd-amdhsa-hcc -mcpu=gfx" + \
152+
std::to_string(val.operator int())+ target.substr(4, target.length() - 4));
141153

142154
std::unique_ptr<CodeGenAMDGPU> cg(new CodeGenAMDGPU());
143155
std::unique_ptr<llvm::LLVMContext> ctx(new llvm::LLVMContext());

src/runtime/rocm/rocm_device_api.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ class ROCMDeviceAPI final : public DeviceAPI {
4444
value = 64;
4545
break;
4646
}
47-
case kComputeVersion: return;
47+
case kComputeVersion:
48+
hipDeviceProp_t prop;
49+
ROCM_CALL(hipGetDeviceProperties(&prop, ctx.device_id));
50+
*rv = prop.gcnArch;
51+
return;
4852
}
4953
*rv = value;
5054
}

0 commit comments

Comments
 (0)