Skip to content

Commit

Permalink
Merge pull request #25 from GPUOpen-LibrariesAndSDKs/next-release-3
Browse files Browse the repository at this point in the history
update to 2.5
  • Loading branch information
RichardGe authored Jan 7, 2025
2 parents 8071587 + f41cfa8 commit b9d4a52
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
39 changes: 29 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}")
Expand All @@ -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})
Expand All @@ -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()


Expand All @@ -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()

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
122 changes: 101 additions & 21 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions scripts/bitcodes/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/')
Expand Down
9 changes: 9 additions & 0 deletions scripts/bitcodes/precompile_bitcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/')
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
2
5
cfa5e2a
337242e

0 comments on commit b9d4a52

Please sign in to comment.