@@ -91,6 +91,38 @@ function get_version(file)
9191 return major , minor , patch
9292end
9393
94+
95+ -- find the path of 'Hipcc' from PATH
96+ -- return nil if not exist
97+ -- only works for linux ( for now )
98+ function findHipccPath ()
99+
100+ if os .host () ~= " linux" then
101+ return nil
102+ end
103+
104+ local cmd = ' which hipcc 2>/dev/null'
105+
106+ local f = io.popen (cmd )
107+ local hipccPath = f :read (" *a" )
108+ f :close ()
109+
110+ if hipccPath == nil or hipccPath == ' ' then
111+ print (" hipccPath nil" );
112+ return nil
113+ else
114+ print (" -- hipccPath = " .. hipccPath );
115+ -- Remove any trailing whitespace
116+ hipccPath = hipccPath :gsub (" %s+$" , " " )
117+
118+ -- Extract the directory from the full path
119+ local dir = hipccPath :match (" (.+)/[^/]+$" )
120+ return dir
121+ end
122+ end
123+
124+
125+
94126function get_hip_sdk_verion ()
95127
96128 if os .ishost (" windows" ) then
@@ -100,33 +132,68 @@ function get_hip_sdk_verion()
100132 hipCommand = ' hipcc'
101133 HIP_PATH = os.getenv (" HIP_PATH" )
102134 PATH = os.getenv (" PATH" )
103- hipInPath = false
104-
105- -- check if HIP is in the PATH environement variable
106- for token in string.gmatch (PATH , " [^;]+" ) do
107- if string.find (token , ' hip' ) then
108- if os .isfile (path .join (token , ' hipcc' )) then
109- hipInPath = true
110- end
111- end
135+
136+
137+
138+ hipccFromPATH = findHipccPath ()
139+ if fromPATH ~= nil then
140+ print ( " hipcc found from PATH: " .. hipccFromPATH )
112141 end
113142
143+
144+
114145 if os .ishost (" windows" ) then
115- if hipInPath then
116- hipCommand = ' hipcc'
117- elseif not HIP_PATH then
118- hipCommand = root .. ' hipSdk\\ bin\\ hipcc'
119- else
146+
147+
148+ if not HIP_PATH then
149+ -- if the HIP_PATH env var is not set, we assume there is a 'hipSdk' folder at the root of the project.
150+ HIP_PATH = path .getabsolute (root .. ' hipSdk' ) -- convert the path to absolute
151+ end
152+
120153 if string.sub (HIP_PATH , - 1 , - 1 ) == ' \\ ' or string.sub (HIP_PATH , - 1 , - 1 ) == ' /' then
121154 HIP_PATH = string.sub (HIP_PATH , 1 , - 2 )
122155 end
156+
123157 -- HIP_PATH is expected to look like: C:\Program Files\AMD\ROCm\5.7
124- hipCommand = ' \" ' .. HIP_PATH .. ' \\ bin\\ ' .. hipCommand .. ' \" '
158+ print (" using HIP_PATH = " .. HIP_PATH )
159+
160+ if os .isfile (HIP_PATH .. ' \\ bin\\ hipcc.exe' ) then
161+ -- in newer version of HIP SDK (>= 6.3), we are using 'hipcc.exe --version' to check the version
162+ -- print("using hipcc.exe to get the version.")
163+ hipCommand = ' \" ' .. HIP_PATH .. ' \\ bin\\ hipcc.exe\" '
164+ elseif os .isfile (HIP_PATH .. ' \\ bin\\ hipcc' ) then
165+ -- in older version of HIP SDK, we are using 'perl hipcc --version' to check the version
166+ -- print("using perl hipcc to get the version.")
167+ hipCommand = ' \" ' .. HIP_PATH .. ' \\ bin\\ hipcc\" '
168+ else
169+ print (" ERROR: hipcc.exe or hipcc not found in the SDK path." )
170+ hipCommand = ' hipcc'
171+ end
172+
173+ -- for LINUX
174+ else
175+
176+ if not HIP_PATH then
177+ if hipccFromPATH ~= nil then
178+ hipCommand = ' hipcc'
179+ end
180+
181+ -- if HIP_PATH is set, we take the path from it.
182+ else
183+ if string.sub (HIP_PATH , - 1 , - 1 ) == ' \\ ' or string.sub (HIP_PATH , - 1 , - 1 ) == ' /' then
184+ HIP_PATH = string.sub (HIP_PATH , 1 , - 2 )
185+ end
186+
187+ hipCommand = ' \" ' .. HIP_PATH .. ' /bin/hipcc\" '
125188 end
189+
126190 end
127191
192+
128193 tmpFile = os.tmpname ()
129- os.execute (hipCommand .. " --version > " .. tmpFile )
194+ fullcommand = hipCommand .. " --version > " .. tmpFile
195+ print (" Executing: " .. fullcommand );
196+ os.execute (fullcommand )
130197
131198 local version
132199 for line in io.lines (tmpFile ) do
@@ -140,9 +207,19 @@ function get_hip_sdk_verion()
140207 version = " HIP_SDK_NOT_FOUND"
141208 end
142209
143- return version
210+ return version , HIP_PATH
144211end
145-
212+
213+
214+
215+ hipSdkVersion , hipFinalPath = get_hip_sdk_verion ()
216+ print ( " HIP_VERSION_STR: " .. hipSdkVersion )
217+ if hipFinalPath ~= nil then
218+ print ( " HIP SDK path: " .. hipFinalPath )
219+ else
220+ print ( " no HIP SDK folder found." )
221+ end
222+
146223function write_version_info (in_file , header_file , version_file )
147224 if not file_exists (version_file ) then
148225 print (" Version.txt file missing!\n " )
@@ -164,8 +241,6 @@ function write_version_info(in_file, header_file, version_file)
164241 header = header :gsub (" @HIPRT_PATCH_VERSION@" , HIPRT_PATCH_VERSION )
165242 header = header :gsub (" @HIPRT_API_VERSION@" , HIPRT_API_VERSION )
166243 header = header :gsub (" @HIPRT_VERSION_STR@" , " \" " .. HIPRT_VERSION_STR .. " \" " )
167- hipSdkVersion = get_hip_sdk_verion ()
168- print ( " HIP_VERSION_STR: " .. hipSdkVersion )
169244 header = header :gsub (" @HIP_VERSION_STR@" , " \" " .. hipSdkVersion .. " \" " )
170245 file = io.open (header_file , " w" )
171246 file :write (header )
@@ -236,7 +311,12 @@ workspace "hiprt"
236311 end
237312
238313 if _OPTIONS [" precompile" ] then
239- os.execute ( " cd ./scripts/bitcodes/ && python compile.py" )
314+ cmdExec = " cd ./scripts/bitcodes/ && python compile.py"
315+ if hipFinalPath ~= nil then
316+ cmdExec = cmdExec .. " --hipSdkPath \" " .. hipFinalPath .. " \" "
317+ end
318+ print (" Executing: " .. cmdExec );
319+ os.execute ( cmdExec )
240320 end
241321
242322 if _OPTIONS [" bakeKernel" ] or _OPTIONS [" bitcode" ] then
0 commit comments