From f41cfa891d970cf7ffa7c02bec559226f93f0848 Mon Sep 17 00:00:00 2001 From: Richard Geslot Date: Tue, 7 Jan 2025 16:44:02 +0100 Subject: [PATCH] update to 2.5 --- CHANGELOG.md | 6 ++ CMakeLists.txt | 39 ++++++-- README.md | 10 +- premake5.lua | 122 ++++++++++++++++++++----- scripts/bitcodes/compile.py | 7 ++ scripts/bitcodes/precompile_bitcode.py | 9 ++ version.txt | 2 +- 7 files changed, 159 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b6b9f9..3d5b848 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +2.5.cfa5e2a +- More flexible vector types +- Unifying math into a single header +- Collapse crash fix +- Other minor fixes + 2.4.c587aa7 - H-PLOC and improved wide BVH conversion - CMake support diff --git a/CMakeLists.txt b/CMakeLists.txt index 9850a87..764ffad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,8 +106,9 @@ endfunction() - -function(get_hip_sdk_version result) +# 'result' is the HIP version as string, for example: 6.2 +# 'result_path' is the output of the path to HIP, for example: C:\Program Files\AMD\ROCm\6.2 +function(get_hip_sdk_version result result_path) if(WIN32) set(root ".\\") endif() @@ -118,7 +119,6 @@ function(get_hip_sdk_version result) set(useHipFromPATH OFF) - # Check if HIP_PATH is defined as a CMake parameter if(DEFINED HIP_PATH) message(STATUS "HIP_PATH is defined as a CMake parameter: ${HIP_PATH}") @@ -131,8 +131,10 @@ function(get_hip_sdk_version result) # if HIP_PATH is not in cmake, and not in environment variable else() - message(STATUS "WARNING: HIP_PATH is not defined as a CMake parameter or an environment variable - not recommended") + message(WARNING "WARNING: HIP_PATH is not defined as a CMake parameter or an environment variable - NOT RECOMMENDED") + # TODO: improve that, but it's not recommanded to use the cmake script without defining HIP_PATH anyway... + set(${result_path} "UNKONWN_PATH" PARENT_SCOPE) # Check if HIP is in the PATH environment variable string(REPLACE ";" "\n" PATH_LIST ${PATH}) @@ -152,6 +154,7 @@ function(get_hip_sdk_version result) if ( HIP_PATH ) remove_trailing_slash(HIP_PATH) # message(STATUS "HIP_PATH formatted: ${HIP_PATH}") + set(${result_path} ${HIP_PATH} PARENT_SCOPE) endif() @@ -167,8 +170,21 @@ function(get_hip_sdk_version result) set(hipCommand "hipSdk\\bin\\hipcc") endif() else() + # HIP_PATH is expected to look like: C:\Program Files\AMD\ROCm\5.7 - set(hipCommand "${HIP_PATH}\\bin\\${hipCommand}") + + if(EXISTS "${HIP_PATH}\\bin\\hipcc.exe") + # in newer version of HIP SDK (>= 6.3), we are using 'hipcc.exe --version' to check the version + # message(STATUS "using hipcc.exe to get the version") + set(exec_perl "") + set(hipCommand "${HIP_PATH}\\bin\\hipcc.exe") + else() + # in older version of HIP SDK, we are using 'perl hipcc --version' to check the version + # message(STATUS "using perl hipcc to get the version") + set(hipCommand "${HIP_PATH}\\bin\\${hipCommand}") + endif() + + endif() endif() @@ -200,9 +216,10 @@ endfunction() # fill the HIP_VERSION_STR variable, it will look like: "6.2" -get_hip_sdk_version(HIP_VERSION_STR) +# also get the path to hip that'll be used along all this cmake. +get_hip_sdk_version(HIP_VERSION_STR HIP_FINAL_PATH) message(STATUS "HIP_VERSION_STR = ${HIP_VERSION_STR}") - +message(STATUS "HIP_FINAL_PATH = ${HIP_FINAL_PATH}") function(write_version_info in_file header_file version_file version_str_out) @@ -346,14 +363,16 @@ endif() # precompile kernels: if(PRECOMPILE) + message(">> Execute: ${PYTHON_EXECUTABLE} compile.py --nvidia --hipSdkPath \"${HIP_FINAL_PATH}\"") execute_process( - COMMAND ${PYTHON_EXECUTABLE} compile.py --nvidia --hipSdkPath ${HIP_PATH} + COMMAND ${PYTHON_EXECUTABLE} compile.py --nvidia --hipSdkPath \"${HIP_FINAL_PATH}\" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/bitcodes ) - + if(NOT NO_UNITTEST) + message(">> Execute: ${PYTHON_EXECUTABLE} precompile_bitcode.py --nvidia --hipSdkPath \"${HIP_FINAL_PATH}\"") execute_process( - COMMAND ${PYTHON_EXECUTABLE} precompile_bitcode.py --nvidia --hipSdkPath ${HIP_PATH} + COMMAND ${PYTHON_EXECUTABLE} precompile_bitcode.py --nvidia --hipSdkPath \"${HIP_FINAL_PATH}\" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/bitcodes ) endif() diff --git a/README.md b/README.md index 815cd3b..2341e14 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,14 @@ This is the main repository for the source code for HIPRT. Then, you can use either premake or cmake.    On Windows with premake: -   5. `.\tools\premake5\win\premake5.exe vs2022` -   6. `Open build\hiprt.sln with Visual Studio 2022.` +   5. `set HIP_PATH=C:\Program Files\AMD\ROCm\6.2\` (optional: change default HIP SDK path) +   6. `.\tools\premake5\win\premake5.exe vs2022` +   7. `Open build\hiprt.sln with Visual Studio 2022.`    On Linux with premake: -   5. `./tools/premake5/linux64/premake5 gmake` -   6. `make -C build -j config=release_x64` +   5. `export HIP_PATH=/opt/rocm` (optional: change default HIP SDK path) +   6. `./tools/premake5/linux64/premake5 gmake` +   7. `make -C build -j config=release_x64`    Example with Cmake on Windows:    5. `mkdir build` diff --git a/premake5.lua b/premake5.lua index 8ebcb37..bc4f1c1 100644 --- a/premake5.lua +++ b/premake5.lua @@ -91,6 +91,38 @@ function get_version(file) return major, minor, patch end + +-- find the path of 'Hipcc' from PATH +-- return nil if not exist +-- only works for linux ( for now ) +function findHipccPath() + + if os.host() ~= "linux" then + return nil + end + + local cmd = 'which hipcc 2>/dev/null' + + local f = io.popen(cmd) + local hipccPath = f:read("*a") + f:close() + + if hipccPath == nil or hipccPath == '' then + print("hipccPath nil"); + return nil + else + print("-- hipccPath = " .. hipccPath ); + -- Remove any trailing whitespace + hipccPath = hipccPath:gsub("%s+$", "") + + -- Extract the directory from the full path + local dir = hipccPath:match("(.+)/[^/]+$") + return dir + end +end + + + function get_hip_sdk_verion() if os.ishost("windows") then @@ -100,33 +132,68 @@ function get_hip_sdk_verion() hipCommand = 'hipcc' HIP_PATH = os.getenv("HIP_PATH") PATH = os.getenv("PATH") - hipInPath = false - - -- check if HIP is in the PATH environement variable - for token in string.gmatch(PATH, "[^;]+") do - if string.find(token, 'hip') then - if os.isfile(path.join(token, 'hipcc')) then - hipInPath = true - end - end + + + + hipccFromPATH = findHipccPath() + if fromPATH ~= nil then + print( "hipcc found from PATH: ".. hipccFromPATH ) end + + if os.ishost("windows") then - if hipInPath then - hipCommand = 'hipcc' - elseif not HIP_PATH then - hipCommand = root .. 'hipSdk\\bin\\hipcc' - else + + + if not HIP_PATH then + -- if the HIP_PATH env var is not set, we assume there is a 'hipSdk' folder at the root of the project. + HIP_PATH = path.getabsolute(root .. 'hipSdk') -- convert the path to absolute + end + if string.sub(HIP_PATH, -1, -1) == '\\' or string.sub(HIP_PATH, -1, -1) == '/' then HIP_PATH = string.sub(HIP_PATH, 1, -2) end + -- HIP_PATH is expected to look like: C:\Program Files\AMD\ROCm\5.7 - hipCommand = '\"' .. HIP_PATH..'\\bin\\'..hipCommand .. '\"' + print("using HIP_PATH = " .. HIP_PATH) + + if os.isfile(HIP_PATH .. '\\bin\\hipcc.exe') then + -- in newer version of HIP SDK (>= 6.3), we are using 'hipcc.exe --version' to check the version + -- print("using hipcc.exe to get the version.") + hipCommand = '\"' .. HIP_PATH..'\\bin\\hipcc.exe\"' + elseif os.isfile(HIP_PATH .. '\\bin\\hipcc') then + -- in older version of HIP SDK, we are using 'perl hipcc --version' to check the version + -- print("using perl hipcc to get the version.") + hipCommand = '\"' .. HIP_PATH..'\\bin\\hipcc\"' + else + print("ERROR: hipcc.exe or hipcc not found in the SDK path.") + hipCommand = 'hipcc' + end + + -- for LINUX + else + + if not HIP_PATH then + if hipccFromPATH ~= nil then + hipCommand = 'hipcc' + end + + -- if HIP_PATH is set, we take the path from it. + else + if string.sub(HIP_PATH, -1, -1) == '\\' or string.sub(HIP_PATH, -1, -1) == '/' then + HIP_PATH = string.sub(HIP_PATH, 1, -2) + end + + hipCommand = '\"' .. HIP_PATH..'/bin/hipcc\"' end + end + tmpFile = os.tmpname () - os.execute (hipCommand .. " --version > " .. tmpFile) + fullcommand = hipCommand .. " --version > " .. tmpFile + print("Executing: " .. fullcommand); + os.execute (fullcommand) local version for line in io.lines (tmpFile) do @@ -140,9 +207,19 @@ function get_hip_sdk_verion() version = "HIP_SDK_NOT_FOUND" end - return version + return version, HIP_PATH end - + + + +hipSdkVersion, hipFinalPath = get_hip_sdk_verion() +print( "HIP_VERSION_STR: "..hipSdkVersion ) +if hipFinalPath ~= nil then + print( "HIP SDK path: " .. hipFinalPath ) +else + print( "no HIP SDK folder found." ) +end + function write_version_info(in_file, header_file, version_file) if not file_exists(version_file) then print("Version.txt file missing!\n") @@ -164,8 +241,6 @@ function write_version_info(in_file, header_file, version_file) header = header:gsub("@HIPRT_PATCH_VERSION@", HIPRT_PATCH_VERSION) header = header:gsub("@HIPRT_API_VERSION@", HIPRT_API_VERSION) header = header:gsub("@HIPRT_VERSION_STR@", "\""..HIPRT_VERSION_STR.."\"") - hipSdkVersion = get_hip_sdk_verion() - print( "HIP_VERSION_STR: "..hipSdkVersion ) header = header:gsub("@HIP_VERSION_STR@", "\""..hipSdkVersion.."\"") file = io.open(header_file, "w") file:write(header) @@ -236,7 +311,12 @@ workspace "hiprt" end if _OPTIONS["precompile"] then - os.execute( "cd ./scripts/bitcodes/ && python compile.py") + cmdExec = "cd ./scripts/bitcodes/ && python compile.py" + if hipFinalPath ~= nil then + cmdExec = cmdExec .. " --hipSdkPath \"" .. hipFinalPath .. "\"" + end + print("Executing: " .. cmdExec); + os.execute( cmdExec ) end if _OPTIONS["bakeKernel"] or _OPTIONS["bitcode"] then diff --git a/scripts/bitcodes/compile.py b/scripts/bitcodes/compile.py index a579dba..b1b44a1 100644 --- a/scripts/bitcodes/compile.py +++ b/scripts/bitcodes/compile.py @@ -96,6 +96,7 @@ def compileAmd(): 'gfx900', 'gfx902', 'gfx904', 'gfx906', 'gfx908', 'gfx909', 'gfx90a', 'gfx90c', 'gfx940', 'gfx941', 'gfx942'] # Vega if hip_sdk_version_num >= 62: # Navi4 supported from 6.2 + gpus.append('gfx1200') gpus.append('gfx1201') if hip_sdk_version_num >= 61: # Strix supported from 6.1 @@ -123,6 +124,12 @@ def compileAmd(): print('export built programs ...') sys.stdout.flush() + + if not os.path.exists(root + 'dist/bin/Debug/'): + os.makedirs(root + 'dist/bin/Debug/') + if not os.path.exists(root + 'dist/bin/Release/'): + os.makedirs(root + 'dist/bin/Release/') + if isLinux(): os.system('cp *.hipfb ' + root + 'dist/bin/Debug/') os.system('cp *.hipfb ' + root + 'dist/bin/Release/') diff --git a/scripts/bitcodes/precompile_bitcode.py b/scripts/bitcodes/precompile_bitcode.py index 85bc709..2700fc3 100644 --- a/scripts/bitcodes/precompile_bitcode.py +++ b/scripts/bitcodes/precompile_bitcode.py @@ -102,6 +102,7 @@ def compileAmd(): hip_version = hip_sdk_version_major +"."+ hip_sdk_version_minor if hip_sdk_version_num >= 62: # Navi4 supported from 6.2 + gpus.append('gfx1200') gpus.append('gfx1201') if hip_sdk_version_num >= 61: # Strix supported from 6.1 @@ -134,6 +135,14 @@ def compileAmd(): print('export built programs ...') sys.stdout.flush() + + if not os.path.exists(root + 'dist/bin/Debug/'): + os.makedirs(root + 'dist/bin/Debug/') + if not os.path.exists(root + 'dist/bin/Release/'): + os.makedirs(root + 'dist/bin/Release/') + if not os.path.exists(root + 'hiprt/bitcodes/'): + os.makedirs(root + 'hiprt/bitcodes/') + if isLinux(): os.system('cp *.hipfb ' + root + 'dist/bin/Debug/') os.system('cp *.hipfb ' + root + 'dist/bin/Release/') diff --git a/version.txt b/version.txt index eca035c..600366d 100644 --- a/version.txt +++ b/version.txt @@ -1,3 +1,3 @@ 2 5 -cfa5e2a +337242e