From b40c3882077e9394bf4465dba48219a368c6f692 Mon Sep 17 00:00:00 2001 From: Paulius Velesko Date: Thu, 30 Apr 2026 02:15:41 +0300 Subject: [PATCH 1/4] cmake: add chipStar/SPIRV platform support to FindHIP --- cmake/FindHIP.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/FindHIP.cmake b/cmake/FindHIP.cmake index 99ad26c32..b80dc3a94 100644 --- a/cmake/FindHIP.cmake +++ b/cmake/FindHIP.cmake @@ -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) From 07f96990b82fa0744cbaca5ddb0234750fb2ae65 Mon Sep 17 00:00:00 2001 From: Paulius Velesko Date: Thu, 30 Apr 2026 02:16:45 +0300 Subject: [PATCH 2/4] dpcpp: update to SYCL 2020 include path sycl/sycl.hpp --- src/occa/internal/lang/modes/dpcpp.cpp | 3 +-- src/occa/internal/modes/dpcpp/polyfill.hpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/occa/internal/lang/modes/dpcpp.cpp b/src/occa/internal/lang/modes/dpcpp.cpp index eea56cd79..3a0bf751f 100644 --- a/src/occa/internal/lang/modes/dpcpp.cpp +++ b/src/occa/internal/lang/modes/dpcpp.cpp @@ -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 \n using namespace sycl;\n")))); + directiveToken(root.source->origin, "include \n using namespace sycl;\n")))); } void dpcppParser::addExtensions() diff --git a/src/occa/internal/modes/dpcpp/polyfill.hpp b/src/occa/internal/modes/dpcpp/polyfill.hpp index 68280e6ac..a2766af87 100644 --- a/src/occa/internal/modes/dpcpp/polyfill.hpp +++ b/src/occa/internal/modes/dpcpp/polyfill.hpp @@ -4,7 +4,7 @@ #define OCCA_MODES_DPCPP_POLYFILL_HEADER #if OCCA_DPCPP_ENABLED -#include +#include #else #include #include From 427f34383dddf7fbb7e5ca2365445ebe18be577a Mon Sep 17 00:00:00 2001 From: Paulius Velesko Date: Thu, 30 Apr 2026 02:17:05 +0300 Subject: [PATCH 3/4] tests/forLoop: qualify int2/int3 with occa:: namespace --- tests/src/loops/forLoop.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/src/loops/forLoop.cpp b/tests/src/loops/forLoop.cpp index 4b6a2418f..6f9614616 100644 --- a/tests/src/loops/forLoop.cpp +++ b/tests/src/loops/forLoop.cpp @@ -1,9 +1,6 @@ #include #include -// TODO: Handle occa:: types in OKL -using int2 = occa::int2; -using int3 = occa::int3; void testOuterForLoops(occa::device device); void testFullForLoops(occa::device device); @@ -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 = ( @@ -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 = ( @@ -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)) ); @@ -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))) ); @@ -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) ); @@ -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)) ); From bdf20f143e39b779f8eb087b707ededdf76ac462 Mon Sep 17 00:00:00 2001 From: Paulius Velesko Date: Thu, 30 Apr 2026 02:18:30 +0300 Subject: [PATCH 4/4] hip: branch on platform macros for arch and compiler flags --- src/occa/internal/modes/hip/device.cpp | 26 +++++++++++++------------- src/occa/internal/modes/hip/utils.cpp | 22 +++++++++------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/occa/internal/modes/hip/device.cpp b/src/occa/internal/modes/hip/device.cpp index 56678c6b7..0f5cebd57 100644 --- a/src/occa/internal/modes/hip/device.cpp +++ b/src/occa/internal/modes/hip/device.cpp @@ -215,21 +215,21 @@ namespace occa { kernelProps.get("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("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("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, diff --git a/src/occa/internal/modes/hip/utils.cpp b/src/occa/internal/modes/hip/utils.cpp index 7b90aef41..91e0ebb79 100644 --- a/src/occa/internal/modes/hip/utils.cpp +++ b/src/occa/internal/modes/hip/utils.cpp @@ -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) {