Skip to content

Commit

Permalink
feat: introduce xmake for cuda
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Sep 9, 2024
1 parent 9483e90 commit af12536
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions template/cuda/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"github_username": "your-org-or-username",

"cxx_build_tool": ["xmake", "cmake"],
"cuda_standard_version": "17",
"cxx_standard_version": "20",

"__gh_slug": "{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}",
Expand Down
4 changes: 2 additions & 2 deletions template/cuda/{{cookiecutter.project_slug}}/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ project({{cookiecutter.project_slug}}
# ===================== Build Settings =====================

# Set C++ and CUDA standards
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CXX_STANDARD {{cookiecutter.cxx_standard_version}})
set(CMAKE_CUDA_STANDARD {{cookiecutter.cuda_standard_version}})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down
8 changes: 7 additions & 1 deletion template/cuda/{{cookiecutter.project_slug}}/tests/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ target("{{cookiecutter.project_slug}}-tests")
set_kind("binary")
add_files("*.cpp")
add_deps("{{cookiecutter.package_name}}_lib")
add_packages("gtest")
add_packages("gtest", "cuda")
add_links("cudart", "cublas")

-- Define test run command
after_build(function (target)
os.exec("%s", target:targetfile())
end)
22 changes: 14 additions & 8 deletions template/cuda/{{cookiecutter.project_slug}}/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
-- Set project name and language
-- Specify the project details
set_project("{{cookiecutter.project_slug}}")
set_languages("c++{{cookiecutter.cxx_standard_version}}")
set_version("0.0.1")

-- Include directories
add_includedirs("include")
-- Specify languages
set_languages("cxx{{cookiecutter.cxx_standard_version}}", "cuda{{cookiecutter.cuda_standard_version}}")

-- Add targets
-- Define the target for the library
target("{{cookiecutter.package_name}}_lib")
set_targetdir("build/lib")
set_kind("static")
add_files("src/*.cpp")
add_headerfiles("include/*.h")
add_files("src/**.cpp", "src/**.cu")
add_includedirs("include", {public = true})
add_defines("CUDA_SEPARABLE_COMPILATION")
add_packages("cuda")
add_links("cudart", "cublas")

-- Define the target for the executable
target("{{cookiecutter.project_slug}}")
set_targetdir("build/bin")
set_kind("binary")
add_files("src/main.cpp")
add_deps("{{cookiecutter.package_name}}_lib")
add_packages("cuda")
add_links("cudart", "cublas")

-- Add tests
-- Add the tests
includes("tests")

0 comments on commit af12536

Please sign in to comment.