Skip to content

Commit 7ace4b1

Browse files
committed
♻️ Refactor premake add a function that calls CUDA
1 parent 5277bae commit 7ace4b1

File tree

1 file changed

+40
-49
lines changed

1 file changed

+40
-49
lines changed

Plugin/premake5.lua

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ function loadrequire(module, linkToRepository)
3535
end
3636
end
3737

38+
function addCUDAToProject(sourceDir, objDir)
39+
buildcustomizations "BuildCustomizations/CUDA 12.2"
40+
-- CUDA specific properties
41+
42+
cudaIntDir(objDir)
43+
cudaFiles
44+
{
45+
sourceDir .. "/**.cu"
46+
}
47+
48+
cudaFastMath "On"
49+
cudaRelocatableCode "On"
50+
cudaMaxRegCount "32"
51+
52+
-- Let's compile for all supported architectures (and also in parallel with -t0)
53+
cudaCompilerOptions { "-gencode=arch=compute_52,code=sm_52", "-gencode=arch=compute_75,code=sm_75",
54+
"-gencode=arch=compute_80,code=sm_80",
55+
"-gencode=arch=compute_86,code=sm_86", "-t0", "-Wreorder", "-Werror=reorder", "-err-no", "-Xcompiler=/wd4505" }
56+
57+
filter "configurations:debug"
58+
cudaLinkerOptions { "-g", "-Xcompiler=/wd4100" }
59+
filter {}
60+
61+
filter "configurations:release"
62+
cudaFastMath "On"
63+
filter {}
64+
end
65+
3866
local root = "./"
3967
local pathTarget = "../InteropUnityCUDA/Assets/Runtime/Plugin"
4068
local pathSampleProject = "SampleBasic"
@@ -98,7 +126,8 @@ local rootProject = pathPluginInterop
98126
location(rootProject)
99127
language "C++"
100128
targetdir(pathTarget, "SampleBasic")
101-
objdir(rootProject .. "/temp/")
129+
local tempDir = rootProject .. "/temp/"
130+
objdir(tempDir)
102131
kind "SharedLib"
103132

104133
local SourceDir = rootProject .. "/src/";
@@ -142,31 +171,9 @@ links { "GL", nameUtilitiesLib }
142171
filter {}
143172

144173

145-
-- Add necessary build customization using standard Premake5
146-
-- This assumes you have installed Visual Studio integration for CUDA
147-
-- Here we have it set to 11.4
148-
buildcustomizations "BuildCustomizations/CUDA 12.2"
149-
-- cudaPath "/usr/local/cuda" -- Only affects linux, because the windows builds get CUDA from the VS extension
150-
151-
-- CUDA specific properties
152-
cudaFiles { SourceDir .. "**.cu" }
153-
cudaMaxRegCount "32"
154-
155-
-- Let's compile for all supported architectures (and also in parallel with -t0)
156-
cudaCompilerOptions { "-arch=sm_52", "-gencode=arch=compute_52,code=sm_52", "-gencode=arch=compute_60,code=sm_60",
157-
"-gencode=arch=compute_61,code=sm_61", "-gencode=arch=compute_70,code=sm_70",
158-
"-gencode=arch=compute_75,code=sm_75", "-gencode=arch=compute_80,code=sm_80",
159-
"-gencode=arch=compute_86,code=sm_86", "-gencode=arch=compute_86,code=compute_86", "-t0" }
160-
161-
-- On Windows, the link to cudart is done by the CUDA extension, but on Linux, this must be done manually
162-
if os.target() == "linux" then
163-
linkoptions { "-L/usr/local/cuda/lib64 -lcudart" }
164-
end
165-
166-
filter "configurations:release"
167-
cudaFastMath "On" -- enable fast math for release
168-
filter ""
169-
174+
sourceDirAbsolute = path.getabsolute(SourceDir)
175+
objDirAbsolute = path.getabsolute(tempDir)
176+
addCUDAToProject(sourceDirAbsolute, objDirAbsolute)
170177

171178

172179

@@ -179,7 +186,8 @@ local rootProject = root .. locationProject
179186
location(rootProject)
180187
language "C++"
181188
targetdir(pathTarget)
182-
objdir(rootProject .. "/temp/")
189+
local tempDir = rootProject .. "/temp/"
190+
objdir(tempDir)
183191
kind "SharedLib"
184192

185193
local SourceDir = rootProject .. "/src/";
@@ -262,7 +270,8 @@ location(rootProject)
262270
kind "SharedLib"
263271
language "C++"
264272
targetdir(pathTarget)
265-
objdir(rootProject .. "/temp/" .. locationProject)
273+
local tempDir = rootProject .. "/temp/"
274+
objdir(tempDir)
266275

267276
local SourceDir = rootProject .. "/src/";
268277
local IncludeDir = pathUtilitiesInclude;
@@ -287,24 +296,6 @@ flags {}
287296
defines { "UTILITIES_SHARED", "UTILITIES_SHARED_EXPORTS" }
288297
symbols "On"
289298

290-
-- Add necessary build customization using standard Premake5
291-
-- This assumes you have installed Visual Studio integration for CUDA
292-
-- Here we have it set to 11.4
293-
buildcustomizations "BuildCustomizations/CUDA 12.2"
294-
-- cudaPath "/usr/local/cuda" -- Only affects linux, because the windows builds get CUDA from the VS extension
295-
296-
cudaMaxRegCount "32"
297-
-- Let's compile for all supported architectures (and also in parallel with -t0)
298-
cudaCompilerOptions { "-arch=sm_52", "-gencode=arch=compute_52,code=sm_52", "-gencode=arch=compute_60,code=sm_60",
299-
"-gencode=arch=compute_61,code=sm_61", "-gencode=arch=compute_70,code=sm_70",
300-
"-gencode=arch=compute_75,code=sm_75", "-gencode=arch=compute_80,code=sm_80",
301-
"-gencode=arch=compute_86,code=sm_86", "-gencode=arch=compute_86,code=compute_86", "-t0" }
302-
303-
-- On Windows, the link to cudart is done by the CUDA extension, but on Linux, this must be done manually
304-
if os.target() == "linux" then
305-
linkoptions { "-L/usr/local/cuda/lib64 -lcudart" }
306-
end
307-
308-
filter "configurations:release"
309-
cudaFastMath "On" -- enable fast math for release
310-
filter ""
299+
sourceDirAbsolute = path.getabsolute(SourceDir)
300+
objDirAbsolute = path.getabsolute(tempDir)
301+
addCUDAToProject(sourceDirAbsolute, objDirAbsolute)

0 commit comments

Comments
 (0)