Skip to content

Commit 5e8e5ac

Browse files
noelchalmersdmed256
authored andcommitted
[HIP] Adding target architecture compiler flag to hipcc command
1 parent 7e555a6 commit 5e8e5ac

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

include/occa/mode/hip/device.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ namespace occa {
8181
const hash_t kernelHash,
8282
const occa::properties &props);
8383

84+
void setArchCompilerFlags(occa::properties &kernelProps);
85+
8486
void compileKernel(const std::string &hashDir,
8587
const std::string &kernelName,
8688
occa::properties &kernelProps,

src/mode/hip/device.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace occa {
4141
device::device(const occa::properties &properties_) :
4242
occa::modeDevice_t(properties_) {
4343

44+
hipDeviceProp_t props;
4445
if (!properties.has("wrapped")) {
4546
OCCA_ERROR("[HIP] device not given a [device_id] integer",
4647
properties.has("device_id") &&
@@ -53,6 +54,9 @@ namespace occa {
5354

5455
OCCA_HIP_ERROR("Device: Creating Context",
5556
hipCtxCreate(&hipContext, 0, hipDevice));
57+
58+
OCCA_HIP_ERROR("Getting device properties",
59+
hipGetDeviceProperties(&props, deviceID));
5660
}
5761

5862
p2pEnabled = false;
@@ -82,6 +86,7 @@ namespace occa {
8286

8387
archMajorVersion = properties.get("hip/arch/major", archMajorVersion);
8488
archMinorVersion = properties.get("hip/arch/minor", archMinorVersion);
89+
properties["kernel/target"] = toString(props.gcnArch);
8590

8691
properties["kernel/verbose"] = properties.get("verbose", false);
8792
}
@@ -339,6 +344,17 @@ namespace occa {
339344
lock);
340345
}
341346

347+
void device::setArchCompilerFlags(occa::properties &kernelProps) {
348+
if (kernelProps.get<std::string>("compiler_flags").find("-t gfx") == std::string::npos) {
349+
std::stringstream ss;
350+
std::string arch = kernelProps["target"];
351+
if (arch.size()) {
352+
ss << " -t gfx" << arch << ' ';
353+
kernelProps["compiler_flags"] += ss.str();
354+
}
355+
}
356+
}
357+
342358
void device::compileKernel(const std::string &hashDir,
343359
const std::string &kernelName,
344360
occa::properties &kernelProps,
@@ -350,6 +366,8 @@ namespace occa {
350366
std::string binaryFilename = hashDir + kc::binaryFile;
351367
const std::string ptxBinaryFilename = hashDir + "ptx_binary.o";
352368

369+
setArchCompilerFlags(kernelProps);
370+
353371
std::stringstream command;
354372

355373
//---[ Compiling Command ]--------
@@ -358,7 +376,7 @@ namespace occa {
358376
<< " --genco "
359377
<< " " << sourceFilename
360378
<< " -o " << binaryFilename
361-
<< ' ' << kernelProps["compilerFlags"]
379+
<< ' ' << kernelProps["compiler_flags"]
362380
#if (OCCA_OS == OCCA_WINDOWS_OS)
363381
<< " -D OCCA_OS=OCCA_WINDOWS_OS -D _MSC_VER=1800"
364382
#endif

src/mode/hip/registration.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace occa {
5252

5353
section
5454
.add("Device ID" , toString(i))
55+
.add("Arch" , "gfx"+toString(props.gcnArch))
5556
.add("Device Name", deviceName)
5657
.add("Memory" , bytesStr)
5758
.addDivider();

0 commit comments

Comments
 (0)