Skip to content

Commit

Permalink
[HIP] Hip updates (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
noelchalmers committed May 4, 2023
1 parent cbdd074 commit be1f7f3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
2 changes: 2 additions & 0 deletions cmake/FindOpenCLWrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if(NOT OpenCL_FOUND)
ENV NVHPC_ROOT
ENV SYCL_ROOT
/usr/local/cuda
/opt/rocm/
/opt/rocm/opencl
/opt/intel/oneapi/compiler/latest/linux
PATH_SUFFIXES
Expand All @@ -32,6 +33,7 @@ if(NOT OpenCL_FOUND)
ENV NVHPC_ROOT
ENV SYCL_ROOT
/usr/local/cuda
/opt/rocm/
/opt/rocm/opencl
/opt/intel/oneapi/compiler/latest/linux
PATH_SUFFIXES
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/shellTools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ function defaultIncludePath {
mergedPaths+=":$CPLUS_INCLUDE_PATH"
mergedPaths+=":$C_INCLUDE_PATH"
mergedPaths+=":$INCLUDEPATH"
mergedPaths+=":/opt/rocm*/opencl/include"
mergedPaths+=":/opt/rocm*/include"
mergedPaths+=":/opt/rocm*/opencl/include"
mergedPaths+=":/usr/local/cuda*/include"
mergedPaths+=":/Developer/NVIDIA/CUDA*/include"
mergedPaths+=":/usr/local/cuda*/targets/*/include/"
Expand All @@ -99,8 +99,8 @@ function defaultLibraryPath {
mergedPaths+=":$OCCA_LIBRARY_PATH"
mergedPaths+=":$LD_LIBRARY_PATH"
mergedPaths+=":$DYLD_LIBRARY_PATH"
mergedPaths+=":/opt/rocm*/opencl/lib/*"
mergedPaths+=":/opt/rocm*/lib"
mergedPaths+=":/opt/rocm*/opencl/lib/*"
mergedPaths+=":/usr/local/cuda*/lib*"
mergedPaths+=":/usr/local/cuda*/lib*/stubs"
mergedPaths+=":/opt/cuda*/lib*"
Expand Down
14 changes: 9 additions & 5 deletions src/occa/internal/modes/hip/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ namespace occa {
if (startsWith(arch, "sm_")) {
archFlag = " -arch=" + arch;
} else if (startsWith(arch, "gfx")) {
#if HIP_VERSION >= 305
#if HIP_VERSION >= 502
archFlag = " --offload-arch=" + arch;
#elif HIP_VERSION >= 305
archFlag = " --amdgpu-target=" + arch;
#else
archFlag = " -t " + arch;
Expand Down Expand Up @@ -243,10 +245,12 @@ namespace occa {
);

if (hipccCompilerFlags.find("-arch=sm") == std::string::npos &&
#if HIP_VERSION >= 305
hipccCompilerFlags.find("-t gfx") == std::string::npos
#else
#if HIP_VERSION >= 502
hipccCompilerFlags.find("--offload-arch=gfx") == std::string::npos
#elif HIP_VERSION >= 305
hipccCompilerFlags.find("--amdgpu-target=gfx") == std::string::npos
#else
hipccCompilerFlags.find("-t gfx") == std::string::npos
#endif
) {
kernelProps["hipcc_compiler_flags"] += " ";
Expand Down Expand Up @@ -320,7 +324,7 @@ namespace occa {
} else if (verbose) {
io::stdout << "Output:\n\n" << commandOutput << "\n";
}

io::sync(binaryFilename);
}

Expand Down
26 changes: 14 additions & 12 deletions src/occa/internal/modes/hip/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,30 @@ namespace occa {
vArgs.resize(args);
}

// HIP expects kernel arguments to be byte-aligned so we add padding to arguments
// HIP expects kernel arguments to be aligned
char *dataPtr = (char*) &(vArgs[0]);
int padding = 0;
int offset = 0;
for (int i = 0; i < args; ++i) {
const kernelArgData &arg = arguments[i];
const udim_t argSize = arg.size();

size_t bytes;
if ((padding + argSize) <= sizeof(void*)) {
bytes = argSize;
padding = sizeof(void*) - padding - argSize;
offset += offset % std::min(static_cast<size_t>(argSize),
sizeof(void*)); //align

const void* val;
if (!arg.isPointer()) {
val = arg.ptr();
} else {
bytes = sizeof(void*);
dataPtr += padding;
padding = 0;
val = &(arg.value.value.ptr);
}

::memcpy(dataPtr, &arg.value.value.int64_, bytes);
dataPtr += bytes;
if (val) {
::memcpy(dataPtr+offset, val, argSize);
}
offset += argSize;
}

size_t size = vArgs.size() * sizeof(vArgs[0]);
size_t size = offset;
void* config[] = {
(void*) HIP_LAUNCH_PARAM_BUFFER_POINTER, &(vArgs[0]),
(void*) HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
Expand Down
3 changes: 2 additions & 1 deletion tests/run_examples
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ for mode in $("${OCCA_DIR}/bin/occa" modes); do
Serial) device="{mode: 'Serial'}";;
OpenMP) device="{mode: 'OpenMP'}";;
CUDA) device="{mode: 'CUDA', device_id: 0}";;
HIP) device="{mode: 'HIP', device_id: 0}";;
OpenCL) device="{mode: 'OpenCL', platform_id: 0, device_id: 0}";;
Metal) device="{mode: 'Metal', device_id: 0}";;
dpcpp) device="{mode: 'dpcpp', platform_id: 0, device_id: 0}";;
Expand All @@ -66,7 +67,7 @@ for mode in $("${OCCA_DIR}/bin/occa" modes); do

# Filters
case "${example_dir}" in

cpp/02_for_loops)
if [[ "${mode}" == OpenCL ]]; then
continue
Expand Down

0 comments on commit be1f7f3

Please sign in to comment.