xmake.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package("cuda")
  2. set_kind("toolchain")
  3. set_homepage("https://developer.nvidia.com/cuda-zone/")
  4. set_description("CUDA® is a parallel computing platform and programming model developed by NVIDIA for general computing on graphical processing units (GPUs).")
  5. if is_plat("windows") then
  6. add_urls("https://developer.download.nvidia.com/compute/cuda/$(version)_windows.exe", {
  7. version = function (version)
  8. local driver_version_map = {
  9. ["12.6.3"] = "561.17",
  10. }
  11. return format("%s/local_installers/cuda_%s_%s", version, version, driver_version_map[tostring(version)])
  12. end})
  13. add_versions("12.6.3", "d73e937c75aaa8114da3aff4eee96f9cae03d4b9d70a30b962ccf3c9b4d7a8e1")
  14. end
  15. add_configs("utils", {description = "Enabled cuda utilities.", default = {}, type = "table"})
  16. add_configs("debug", {description = "Enable debug symbols.", default = false, type = "boolean", readonly = true})
  17. set_policy("package.precompiled", false)
  18. on_fetch(function (package, opt)
  19. if opt.system then
  20. import("detect.sdks.find_cuda")
  21. import("lib.detect.find_library")
  22. local cuda = find_cuda()
  23. if cuda then
  24. local result = {includedirs = cuda.includedirs, linkdirs = cuda.linkdirs, links = {}}
  25. local utils = package:config("utils")
  26. table.insert(utils, package:config("shared") and "cudart" or "cudart_static")
  27. for _, util in ipairs(utils) do
  28. if not find_library(util, cuda.linkdirs) then
  29. wprint(format("The library %s for %s is not found!", util, package:arch()))
  30. return
  31. end
  32. table.insert(result.links, util)
  33. end
  34. return result
  35. end
  36. end
  37. end)
  38. on_load("windows", function (package)
  39. package:mark_as_pathenv("CUDA_PATH")
  40. package:setenv("CUDA_PATH", ".")
  41. end)
  42. on_install("windows|x64", function(package)
  43. import("lib.detect.find_tool")
  44. import("lib.detect.find_directory")
  45. if package:is_plat("windows") then
  46. local z7 = assert(find_tool("7z"), "7z tool not found!")
  47. os.vrunv(z7.program, {"x", "-y", package:originfile()})
  48. -- reference: https://github.com/ScoopInstaller/Main/blob/master/bucket/cuda.json
  49. local names = {"bin", "extras", "include", "lib", "libnvvp", "nvml", "nvvm", "compute-sanitizer"}
  50. for _, dir in ipairs(os.dirs("*")) do
  51. if dir:startswith("cuda_") or dir:startswith("lib") then
  52. for _, name in ipairs(names) do
  53. local util_dir = find_directory(name, path.join(dir, "*"))
  54. if util_dir then
  55. os.vcp(path.join(util_dir, "*"), package:installdir(name))
  56. end
  57. end
  58. end
  59. end
  60. end
  61. end)
  62. on_test(function (package)
  63. if not package:is_cross() then
  64. os.vrun("nvcc -V")
  65. end
  66. end)