Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmake/FindHIP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ if(UNIX AND NOT APPLE AND NOT CYGWIN)
set(HIP_RUNTIME_DEFINE "__HIP_PLATFORM_AMD__")
set(HIP_PLATFORM "hip-clang")
endif()
elseif(${HIP_PLATFORM} STREQUAL "spirv")
set(HIP_INCLUDE_DIRS "${HIP_ROOT_DIR}/include")
set(HIP_LIBRARIES "${HIP_ROOT_DIR}/lib/libCHIP.so")
set(HIP_RUNTIME_DEFINE "__HIP_PLATFORM_SPIRV__")
elseif(${HIP_PLATFORM} STREQUAL "nvidia")
find_package(CUDA)

Expand Down
3 changes: 1 addition & 2 deletions src/occa/internal/lang/modes/dpcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,12 @@ namespace occa
return "";
}

// @note: As of SYCL 2020 this will need to change from `CL/sycl.hpp` to `sycl.hpp`
void dpcppParser::setupHeaders()
{
root.addFirst(
*(new directiveStatement(
&root,
directiveToken(root.source->origin, "include <CL/sycl.hpp>\n using namespace sycl;\n"))));
directiveToken(root.source->origin, "include <sycl/sycl.hpp>\n using namespace sycl;\n"))));
}

void dpcppParser::addExtensions()
Expand Down
2 changes: 1 addition & 1 deletion src/occa/internal/modes/dpcpp/polyfill.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define OCCA_MODES_DPCPP_POLYFILL_HEADER

#if OCCA_DPCPP_ENABLED
#include <sycl.hpp>
#include <sycl/sycl.hpp>
#else
#include <cstdint>
#include <vector>
Expand Down
26 changes: 13 additions & 13 deletions src/occa/internal/modes/hip/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,21 @@ namespace occa {
kernelProps.get<std::string>("hipcc_compiler_flags")
);

if (hipccCompilerFlags.find("-arch=sm") == std::string::npos &&
hipccCompilerFlags.find("--offload-arch=gfx") == std::string::npos) {

#if defined(__HIP_PLATFORM_AMD__)
if (hipccCompilerFlags.find("--offload-arch=") == std::string::npos) {
std::string archString = kernelProps.get<std::string>("arch", arch);

std::string archFlag;
if (startsWith(archString, "sm_")) {
archFlag = " -arch=" + archString;
} else if (startsWith(archString, "gfx")) {
archFlag = " --offload-arch=" + archString;
} else {
OCCA_FORCE_ERROR("Unknown HIP arch");
}
kernelProps["hipcc_compiler_flags"] += archFlag;
kernelProps["hipcc_compiler_flags"] += " --offload-arch=" + archString;
}
#elif defined(__HIP_PLATFORM_NVIDIA__)
if (hipccCompilerFlags.find("-arch=") == std::string::npos) {
std::string archString = kernelProps.get<std::string>("arch", arch);
kernelProps["hipcc_compiler_flags"] += " -arch=" + archString;
}
#elif defined(__HIP_PLATFORM_SPIRV__)
// SPIR-V is architecture-agnostic; no arch flag needed
#else
OCCA_FORCE_ERROR("Unknown HIP platform");
#endif
}

void device::compileKernel(const std::string &hashDir,
Expand Down
22 changes: 9 additions & 13 deletions src/occa/internal/modes/hip/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,19 @@ namespace occa {
}

std::string getDeviceArch(const int deviceId) {
#if defined(__HIP_PLATFORM_AMD__) || defined(__HIP_PLATFORM_SPIRV__)
hipDeviceProp_t hipProps;

OCCA_HIP_ERROR("Getting HIP device properties",
hipGetDeviceProperties(&hipProps, deviceId));

std::string gcnArchName{hipProps.gcnArchName};
if (!gcnArchName.empty()) { // AMD or NVIDIA
return gcnArchName;
}

int archMajorVersion=0, archMinorVersion=0;
return std::string{hipProps.gcnArchName};
#elif defined(__HIP_PLATFORM_NVIDIA__)
int archMajorVersion = 0, archMinorVersion = 0;
getDeviceArchVersion(deviceId, archMajorVersion, archMinorVersion);

std::string arch = "sm_";
arch += toString(archMajorVersion);
arch += toString(archMinorVersion);
return arch;
return "sm_" + toString(archMajorVersion) + toString(archMinorVersion);
#else
OCCA_FORCE_ERROR("Unknown HIP platform");
return "";
#endif
}

void enablePeerToPeer(hipCtx_t context) {
Expand Down
15 changes: 6 additions & 9 deletions tests/src/loops/forLoop.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include <occa.hpp>
#include <occa/internal/utils/testing.hpp>

// TODO: Handle occa:: types in OKL
using int2 = occa::int2;
using int3 = occa::int3;

void testOuterForLoops(occa::device device);
void testFullForLoops(occa::device device);
Expand Down Expand Up @@ -66,7 +63,7 @@ void testOuterForLoops(occa::device device) {

occa::forLoop()
.outer(length, occa::range(length))
.run(OCCA_FUNCTION(scope, [=](const int2 outerIndex) -> void {
.run(OCCA_FUNCTION(scope, [=](const occa::int2 outerIndex) -> void {
OKL("@inner");
for (int i = 0; i < 2; ++i) {
const int globalIndex = (
Expand All @@ -84,7 +81,7 @@ void testOuterForLoops(occa::device device) {

occa::forLoop()
.outer(length, occa::range(length), indexArray)
.run(OCCA_FUNCTION(scope, [=](const int3 outerIndex) -> void {
.run(OCCA_FUNCTION(scope, [=](const occa::int3 outerIndex) -> void {
OKL("@inner");
for (size_t i = 0; i < 2; ++i) {
const int globalIndex = (
Expand Down Expand Up @@ -148,7 +145,7 @@ void testFullForLoops(occa::device device) {
occa::forLoop()
.outer(2)
.inner(length, occa::range(length))
.run(OCCA_FUNCTION(scope, [=](const int outerIndex, const int2 innerIndex) -> void {
.run(OCCA_FUNCTION(scope, [=](const int outerIndex, const occa::int2 innerIndex) -> void {
const int globalIndex = (
outerIndex + (2 * (innerIndex.y + length * innerIndex.x))
);
Expand All @@ -164,7 +161,7 @@ void testFullForLoops(occa::device device) {
occa::forLoop()
.outer(2)
.inner(length, occa::range(length), indexArray)
.run(OCCA_FUNCTION(scope, [=](const int outerIndex, const int3 innerIndex) -> void {
.run(OCCA_FUNCTION(scope, [=](const int outerIndex, const occa::int3 innerIndex) -> void {
const int globalIndex = (
outerIndex + (2 * (innerIndex.z + length * (innerIndex.y + length * innerIndex.x)))
);
Expand Down Expand Up @@ -203,7 +200,7 @@ void testTileForLoops(occa::device device) {

occa::forLoop()
.tile({length, 2}, {occa::range(length), 2})
.run(OCCA_FUNCTION(scope, [=](const int2 index) -> void {
.run(OCCA_FUNCTION(scope, [=](const occa::int2 index) -> void {
const int globalIndex = (
index.x + (length * index.y)
);
Expand All @@ -222,7 +219,7 @@ void testTileForLoops(occa::device device) {
{occa::range(length), 2},
{indexArray, 2}
)
.run(OCCA_FUNCTION(scope, [=](const int3 index) -> void {
.run(OCCA_FUNCTION(scope, [=](const occa::int3 index) -> void {
const int globalIndex = (
index.x + (length * (index.y + length * index.z))
);
Expand Down
Loading