-
Notifications
You must be signed in to change notification settings - Fork 7
/
premake5.lua
333 lines (286 loc) · 9.81 KB
/
premake5.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
newoption {
trigger = "bakeKernel",
description = "Encrypt and bake kernels"
}
newoption {
trigger = "bitcode",
description = "Enable bitcode linking"
}
newoption {
trigger = "precompile",
description = "Precompile kernels"
}
newoption {
trigger = "hiprtew",
description = "Use hiprtew"
}
newoption {
trigger = "noUnittest",
description = "Don't build unit tests",
}
newoption {
trigger = "noEncrypt",
description = "Don't encrypt kernel source and binaries",
}
function copydir(src_dir, dst_dir, filter, single_dst_dir)
filter = filter or "**"
src_dir = src_dir .. "/"
print('copy "' .. src_dir .. filter .. '" to "' .. dst_dir .. '".')
dst_dir = dst_dir .. "/"
local dir = path.rebase(".", path.getabsolute("."), src_dir) -- root dir, relative from src_dir
os.chdir(src_dir) -- change current directory to src_dir
local matches = os.matchfiles(filter)
os.chdir(dir) -- change current directory back to root
local counter = 0
for k, v in ipairs(matches) do
local target = iif(single_dst_dir, path.getname(v), v)
--make sure, that directory exists or os.copyfile() fails
os.mkdir(path.getdirectory(dst_dir .. target))
if os.copyfile(src_dir .. v, dst_dir .. target) then
counter = counter + 1
end
end
if counter == #matches then
print(counter .. " files copied.")
return true
else
print("Error: " .. counter .. "/" .. #matches .. " files copied.")
return nil
end
end
function file_exists(file)
local f = io.open(file, "rb")
if f then f:close() end
return f ~= nil
end
function lines_from(file)
if not file_exists(file) then return {} end
local lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end
function read_file(file)
local lines = lines_from(file)
str = ''
for num, line in pairs(lines) do
str = str..line.."\n"
end
return str
end
function get_version(file)
local lines = lines_from(file)
major = tonumber(lines[1])
minor = tonumber(lines[2])
patch = "0x"..(lines[3])
return major, minor, patch
end
function get_hip_sdk_verion()
if os.ishost("windows") then
root = '.\\'
end
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
end
if os.ishost("windows") then
if hipInPath then
hipCommand = 'hipcc'
elseif not HIP_PATH then
hipCommand = root .. 'hipSdk\\bin\\hipcc'
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
-- HIP_PATH is expected to look like: C:\Program Files\AMD\ROCm\5.7
hipCommand = '\"' .. HIP_PATH..'\\bin\\'..hipCommand .. '\"'
end
end
tmpFile = os.tmpname ()
os.execute (hipCommand .. " --version > " .. tmpFile)
local version
for line in io.lines (tmpFile) do
print (line)
version = string.sub(line, string.find(line, "%d.%d"))
break
end
os.remove (tmpFile)
if version == nil or version == '' then
version = "HIP_SDK_NOT_FOUND"
end
return version
end
function write_version_info(in_file, header_file, version_file)
if not file_exists(version_file) then
print("Version.txt file missing!\n")
return
end
if not file_exists(in_file) then
print(string.format("%s file is missing!\n", in_file))
return
end
HIPRT_MAJOR_VERSION, HIPRT_MINOR_VERSION, HIPRT_PATCH_VERSION = get_version(version_file)
HIPRT_VERSION = HIPRT_MAJOR_VERSION * 1000 + HIPRT_MINOR_VERSION
HIPRT_API_VERSION = HIPRT_VERSION
HIPRT_VERSION_STR = string.format("%05d", HIPRT_VERSION)
print( "HIPRT_API_VERSION: "..HIPRT_VERSION_STR .."_".. HIPRT_PATCH_VERSION )
header = read_file(in_file)
header = header:gsub("@HIPRT_MAJOR_VERSION@", HIPRT_MAJOR_VERSION)
header = header:gsub("@HIPRT_MINOR_VERSION@", HIPRT_MINOR_VERSION)
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)
file:close()
end
workspace "hiprt"
configurations {"Debug", "Release", "RelWithDebInfo", "DebugGpu" }
language "C++"
platforms "x64"
architecture "x86_64"
if os.ishost("windows") then
defines {"__WINDOWS__"}
end
characterset("MBCS")
filter {"platforms:x64", "configurations:Debug or configurations:DebugGpu"}
targetsuffix "64D"
defines {"DEBUG"}
symbols "On"
filter {"platforms:x64", "configurations:DebugGpu"}
defines {"DEBUG_GPU"}
filter {"platforms:x64", "configurations:Release or configurations:RelWithDebInfo"}
targetsuffix "64"
defines {"NDEBUG"}
optimize "On"
filter {"platforms:x64", "configurations:RelWithDebInfo"}
symbols "On"
filter {}
flags { "MultiProcessorCompile" }
if os.ishost("windows") then
buildoptions {"/wd4244", "/wd4305", "/wd4018", "/wd4996", "/Zc:__cplusplus"}
end
if os.ishost("linux") then
buildoptions {"-fvisibility=hidden"}
end
defines {"__USE_HIP__"}
-- this define is to identify that we are on the public repository of HIPRT.
-- it helps AMD to maintain both a public and a private repo for experimentation.
defines {"HIPRT_PUBLIC_REPO"}
-- enable CUDA if possible
include "./contrib/Orochi/Orochi/enable_cuew"
targetdir "dist/bin/%{cfg.buildcfg}"
location "build/"
write_version_info("./hiprt/hiprt.h.in", "./hiprt/hiprt.h", "version.txt")
write_version_info("./hiprt/hiprtew.h.in", "./hiprt/hiprtew.h", "version.txt")
HIPRT_NAME = "hiprt"..HIPRT_VERSION_STR
project( HIPRT_NAME )
cppdialect "C++17"
kind "SharedLib"
defines {"HIPRT_EXPORTS"}
if _OPTIONS["bitcode"] then
defines {"HIPRT_BITCODE_LINKING"}
defines {"ORO_PRECOMPILED"}
end
if not _OPTIONS["no-encrypt"] then
defines {"HIPRT_ENCRYPT"}
end
if _OPTIONS["precompile"] then
os.execute( "cd ./scripts/bitcodes/ && python compile.py")
end
if _OPTIONS["bakeKernel"] or _OPTIONS["bitcode"] then
print(">> BakeKernel Executed")
if os.ishost("windows") then
os.execute("mkdir hiprt\\cache")
os.execute("tools\\bakeKernel.bat")
else
os.execute("mkdir hiprt/cache")
os.execute("./tools/bakeKernel.sh")
end
if _OPTIONS["bakeKernel"] then
defines {"HIPRT_LOAD_FROM_STRING"}
defines { "ORO_PP_LOAD_FROM_STRING" }
end
defines {"HIPRT_BAKE_KERNEL_GENERATED"}
end
if os.istarget("windows") then
links{ "version" }
end
externalincludedirs {"./"}
files {"hiprt/**.h", "hiprt/**.cpp", "hiprt/**.inl"}
removefiles {"hiprt/bitcodes/**"}
externalincludedirs { "./contrib/Orochi/" }
files {"contrib/Orochi/Orochi/**.h", "contrib/Orochi/Orochi/**.cpp"}
files {"contrib/Orochi/contrib/cuew/**.h", "contrib/Orochi/contrib/cuew/**.cpp"}
files {"contrib/Orochi/contrib/hipew/**.h", "contrib/Orochi/contrib/hipew/**.cpp"}
files {"contrib/Orochi/ParallelPrimitives/**.h", "contrib/Orochi/ParallelPrimitives/**.cpp"}
if not _OPTIONS["noUnittest"] then
project( "unittest" )
cppdialect "C++17"
kind "ConsoleApp"
if _OPTIONS["bitcode"] then
defines {"HIPRT_BITCODE_LINKING"}
end
if os.ishost("windows") then
buildoptions { "/wd4244" }
links{ "version" }
end
externalincludedirs {"./"}
links { HIPRT_NAME }
if os.ishost("linux") then
links { "pthread", "dl" }
end
files { "test/hiprtT*.h", "test/hiprtT*.cpp", "test/shared.h", "test/main.cpp", "test/CornellBox.h", "test/kernels/*.h" }
externalincludedirs { "./contrib/Orochi/" }
files {"contrib/Orochi/Orochi/**.h", "contrib/Orochi/Orochi/**.cpp"}
files {"contrib/Orochi/contrib/cuew/**.h", "contrib/Orochi/contrib/cuew/**.cpp"}
files {"contrib/Orochi/contrib/hipew/**.h", "contrib/Orochi/contrib/hipew/**.cpp"}
files { "contrib/gtest-1.6.0/gtest-all.cc" }
externalincludedirs { "contrib/gtest-1.6.0/" }
defines { "GTEST_HAS_TR1_TUPLE=0" }
externalincludedirs { "contrib/embree/include/" }
if os.istarget("windows") then
libdirs{"contrib/embree/win/"}
copydir( "./contrib/embree/win", "./dist/bin/Release/", "*.dll" )
copydir( "./contrib/embree/win", "./dist/bin/Debug/", "*.dll" )
libdirs{"contrib/bin/win64"}
copydir( "./contrib/Orochi/contrib/bin/win64", "./dist/bin/Release/", "*.dll" )
copydir( "./contrib/Orochi/contrib/bin/win64", "./dist/bin/Debug/", "*.dll" )
end
if os.istarget("linux") then
libdirs{"contrib/embree/linux/"}
end
links{ "embree4", "tbb" }
end
if _OPTIONS["hiprtew"] then
project( "hiprtewtest" )
kind "ConsoleApp"
defines {"HIPRT_EXPORTS"}
defines {"USE_HIPRTEW"}
if os.ishost("windows") then
buildoptions { "/wd4244" }
links{ "version" }
end
externalincludedirs {"./", "./contrib/Orochi/"}
if os.ishost("linux") then
links { "pthread", "dl"}
end
files {"contrib/Orochi/Orochi/**.h", "contrib/Orochi/Orochi/**.cpp"}
files {"contrib/Orochi/contrib/**.h", "contrib/Orochi/contrib/**.cpp"}
files { "test/hiprtewTest.h", "test/hiprtewTest.cpp" }
files { "contrib/gtest-1.6.0/gtest-all.cc" }
externalincludedirs { "contrib/gtest-1.6.0/" }
defines { "GTEST_HAS_TR1_TUPLE=0" }
end