-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support for rocm gpu autodetect #549
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,9 +135,15 @@ runtime::Module BuildAMDGPU(Array<LoweredFunc> funcs, std::string target) { | |
CHECK(target.length( | ||
) >= 4 && | ||
target.substr(0, 4) == "rocm"); | ||
TVMContext tvmCtx; | ||
tvmCtx.device_type = kROCM; | ||
tvmCtx.device_id = 0; | ||
TVMRetValue val; | ||
tvm::runtime::DeviceAPI::Get(tvmCtx)->GetAttr(tvmCtx, tvm::runtime::kComputeVersion, &val); | ||
|
||
llvm::TargetMachine* tm = \ | ||
GetLLVMTargetMachine("-mtriple=amdgcn-amd-amdhsa-hcc -mcpu=gfx803" + \ | ||
target.substr(4, target.length() - 4)); | ||
GetLLVMTargetMachine("-mtriple=amdgcn-amd-amdhsa-hcc -mcpu=gfx" + \ | ||
std::to_string(static_cast<int>(val)) + target.substr(4, target.length() - 4)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std::to_string(val.operator int()) |
||
|
||
std::unique_ptr<CodeGenAMDGPU> cg(new CodeGenAMDGPU()); | ||
std::unique_ptr<llvm::LLVMContext> ctx(new llvm::LLVMContext()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,11 @@ class ROCMDeviceAPI final : public DeviceAPI { | |
value = 64; | ||
break; | ||
} | ||
case kComputeVersion: return; | ||
case kComputeVersion: | ||
hipDeviceProp_t prop; | ||
ROCM_CALL(hipGetDeviceProperties(&prop, ctx.device_id)); | ||
value = prop.gcnArch; | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need break here, note how *rv get assigned in line 53 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rookie mistake |
||
} | ||
*rv = value; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be safe, I would first query tvm::runtime::DeviceAPI::Get(tvmCtx)->GetAttr(tvmCtx, tvm::runtime::kExist, &val) to check if device exists, then if it exists, append the gfx arch string, otherwise assign an default