|
|
|
@ -11,9 +11,13 @@ package("libtorch") |
|
|
|
|
add_versions("v1.9.0", "d69c22dd61a2f006dcfe1e3ea8468a3ecaf931aa") |
|
|
|
|
add_versions("v1.9.1", "dfbd030854359207cb3040b864614affeace11ce") |
|
|
|
|
add_versions("v1.11.0", "bc2c6edaf163b1a1330e37a6e34caf8c553e4755") |
|
|
|
|
add_versions("v1.12.1", "664058fa83f1d8eede5d66418abff6e20bd76ca8") |
|
|
|
|
|
|
|
|
|
add_patches("1.9.x", path.join(os.scriptdir(), "patches", "1.9.0", "gcc11.patch"), "4191bb3296f18f040c230d7c5364fb160871962d6278e4ae0f8bc481f27d8e4b") |
|
|
|
|
add_patches("1.11.0", path.join(os.scriptdir(), "patches", "1.11.0", "gcc11.patch"), "1404b0bc6ce7433ecdc59d3412e3d9ed507bb5fd2cd59134a254d7d4a8d73012") |
|
|
|
|
-- Fix compile on macOS. Refer to https://github.com/pytorch/pytorch/pull/80916 |
|
|
|
|
add_patches("1.12.1", path.join(os.scriptdir(), "patches", "1.12.1", "clang.patch"), "cdc3e00b2fea847678b1bcc6b25a4dbd924578d8fb25d40543521a09aab2f7d4") |
|
|
|
|
add_patches("1.12.1", path.join(os.scriptdir(), "patches", "1.12.1", "vs2022.patch"), "5a31b9772793c943ca752c92d6415293f7b3863813ca8c5eb9d92a6156afd21d") |
|
|
|
|
|
|
|
|
|
add_configs("shared", {description = "Build shared library.", default = true, type = "boolean"}) |
|
|
|
|
add_configs("python", {description = "Build python interface.", default = false, type = "boolean"}) |
|
|
|
@ -21,6 +25,8 @@ package("libtorch") |
|
|
|
|
add_configs("cuda", {description = "Enable CUDA support.", default = false, type = "boolean"}) |
|
|
|
|
add_configs("ninja", {description = "Use ninja as build tool.", default = false, type = "boolean"}) |
|
|
|
|
add_configs("blas", {description = "Set BLAS vendor.", default = "openblas", type = "string", values = {"mkl", "openblas", "eigen"}}) |
|
|
|
|
add_configs("pybind11", {description = "Use pybind11 from xrepo.", default = false, type = "boolean"}) |
|
|
|
|
add_configs("protobuf-cpp", {description = "Use protobuf from xrepo.", default = false, type = "boolean"}) |
|
|
|
|
if not is_plat("macosx") then |
|
|
|
|
add_configs("distributed", {description = "Enable distributed support.", default = false, type = "boolean"}) |
|
|
|
|
end |
|
|
|
@ -56,6 +62,12 @@ package("libtorch") |
|
|
|
|
if not package:is_plat("macosx") and package:config("blas") then |
|
|
|
|
package:add("deps", package:config("blas")) |
|
|
|
|
end |
|
|
|
|
if package:config("pybind11") then |
|
|
|
|
package:add("deps", "pybind11") |
|
|
|
|
end |
|
|
|
|
if package:config("protobuf-cpp") then |
|
|
|
|
package:add("deps", "protobuf-cpp") |
|
|
|
|
end |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
on_install("windows|x64", "macosx", "linux", function (package) |
|
|
|
@ -94,13 +106,20 @@ package("libtorch") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
if not package:config("shared") then |
|
|
|
|
for _, lib in ipairs({"nnpack", "pytorch_qnnpack", "qnnpack", "XNNPACK", "caffe2_protos", "protobuf-lite", "protobuf", "protoc", "onnx", "onnx_proto", "foxi_loader", "pthreadpool", "eigen_blas", "fbgemm", "cpuinfo", "clog", "dnnl", "mkldnn", "sleef", "asmjit", "fmt", "kineto"}) do |
|
|
|
|
for _, lib in ipairs({"nnpack", "pytorch_qnnpack", "qnnpack", "XNNPACK", "caffe2_protos", "protobuf-lite", "protobuf", "protoc", "onnx", "onnx_proto", "foxi_loader", "pthreadpool", "eigen_blas", "fbgemm", "cpuinfo", "clog", "dnnl_graph", "dnnl", "mkldnn", "sleef", "asmjit", "fmt", "kineto"}) do |
|
|
|
|
package:add("links", lib) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- some patches to the third-party cmake files |
|
|
|
|
io.replace("third_party/fbgemm/CMakeLists.txt", "PRIVATE FBGEMM_STATIC", "PUBLIC FBGEMM_STATIC", {plain = true}) |
|
|
|
|
-- Workaround to compile with GCC-12. |
|
|
|
|
-- Refer to [this pytorch issue](https://github.com/pytorch/pytorch/issues/77939). |
|
|
|
|
io.replace("third_party/fbgemm/CMakeLists.txt", |
|
|
|
|
'string(APPEND CMAKE_CXX_FLAGS " -Werror")', |
|
|
|
|
'string(APPEND CMAKE_CXX_FLAGS " -Werror")\n string(APPEND CMAKE_CXX_FLAGS " -Wno-uninitialized")', |
|
|
|
|
{plain = true} |
|
|
|
|
) |
|
|
|
|
io.replace("third_party/protobuf/cmake/install.cmake", "install%(DIRECTORY.-%)", "") |
|
|
|
|
if package:is_plat("windows") and package:config("vs_runtime"):startswith("MD") then |
|
|
|
|
io.replace("third_party/fbgemm/CMakeLists.txt", "MT", "MD", {plain = true}) |
|
|
|
@ -142,6 +161,8 @@ package("libtorch") |
|
|
|
|
table.insert(configs, "-DUSE_CUDA=" .. (package:config("cuda") and "ON" or "OFF")) |
|
|
|
|
table.insert(configs, "-DUSE_OPENMP=" .. (package:config("openmp") and "ON" or "OFF")) |
|
|
|
|
table.insert(configs, "-DUSE_DISTRIBUTED=" .. (package:config("distributed") and "ON" or "OFF")) |
|
|
|
|
table.insert(configs, "-DUSE_SYSTEM_PYBIND11=" .. (package:config("pybind11") and "ON" or "OFF")) |
|
|
|
|
table.insert(configs, "-DBUILD_CUSTOM_PROTOBUF=" .. (package:config("protobuf-cpp") and "OFF" or "ON")) |
|
|
|
|
if package:is_plat("windows") then |
|
|
|
|
table.insert(configs, "-DCAFFE2_USE_MSVC_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF")) |
|
|
|
|
end |
|
|
|
@ -151,6 +172,36 @@ package("libtorch") |
|
|
|
|
opt.cmake_generator = "Ninja" |
|
|
|
|
end |
|
|
|
|
cmake.install(package, configs, opt) |
|
|
|
|
|
|
|
|
|
-- These libs are not installed by cmake but are required for static link. |
|
|
|
|
local cp_libs = {"libonnx", "libonnx_proto"} |
|
|
|
|
if package:version():eq("v1.11.0") then |
|
|
|
|
table.insert(cp_libs, "libbreakpad") |
|
|
|
|
table.insert(cp_libs, "libbreakpad_common") |
|
|
|
|
end |
|
|
|
|
local static_lib_suffix = ".a" |
|
|
|
|
if package:is_plat("windows") then |
|
|
|
|
static_lib_suffix = ".lib" |
|
|
|
|
end |
|
|
|
|
for _, libname in ipairs(cp_libs) do |
|
|
|
|
os.trycp(path.join(package:buildir(), "lib", libname .. static_lib_suffix), package:installdir("lib")) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- Following patches are needed for static link. |
|
|
|
|
io.replace( |
|
|
|
|
path.join(package:installdir("share/cmake/Torch/TorchConfig.cmake")), |
|
|
|
|
"append_torchlib_if_found(dnnl mkldnn)", |
|
|
|
|
"append_torchlib_if_found(dnnl_graph dnnl mkldnn)", |
|
|
|
|
{plain = true} |
|
|
|
|
) |
|
|
|
|
if package:version():eq("v1.11.0") then |
|
|
|
|
io.replace( |
|
|
|
|
path.join(package:installdir("share/cmake/Torch/TorchConfig.cmake")), |
|
|
|
|
"append_torchlib_if_found(sleef asmjit)", |
|
|
|
|
"append_torchlib_if_found(sleef asmjit)\n append_torchlib_if_found(breakpad breakpad_common)", |
|
|
|
|
{plain = true} |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
on_test(function (package) |
|
|
|
|