Przeglądaj źródła

update libtorch (#1096)

* update libtorch

* update libuv

* fix libuv

* disable iphoneos
Hoildkv 3 lat temu
rodzic
commit
4b82b7cc80

+ 12 - 0
packages/l/libtorch/patches/1.11.0/gcc11.patch

@@ -0,0 +1,12 @@
+diff --git a/third_party/breakpad/src/client/linux/handler/exception_handler.cc b/third_party/breakpad/src/client/linux/handler/exception_handler.cc
+--- a/third_party/breakpad/src/client/linux/handler/exception_handler.cc
++++ b/third_party/breakpad/src/client/linux/handler/exception_handler.cc
+@@ -138,7 +138,7 @@ void InstallAlternateStackLocked() {
+   // SIGSTKSZ may be too small to prevent the signal handlers from overrunning
+   // the alternative stack. Ensure that the size of the alternative stack is
+   // large enough.
+-  static const unsigned kSigStackSize = std::max(16384, SIGSTKSZ);
++  const unsigned kSigStackSize = std::max<unsigned>(16384, SIGSTKSZ);
+ 
+   // Only set an alternative stack if there isn't already one, or if the current
+   // one is too small.

+ 28 - 14
packages/l/libtorch/xmake.lua

@@ -10,23 +10,24 @@ package("libtorch")
     add_versions("v1.8.2", "e0495a7aa104471d95dc85a1b8f6473fbcc427a8")
     add_versions("v1.9.0", "d69c22dd61a2f006dcfe1e3ea8468a3ecaf931aa")
     add_versions("v1.9.1", "dfbd030854359207cb3040b864614affeace11ce")
+    add_versions("v1.11.0", "bc2c6edaf163b1a1330e37a6e34caf8c553e4755")
 
     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")
 
     add_configs("python", {description = "Build python interface.", default = false, type = "boolean"})
-    add_configs("ninja", {description = "Use ninja as build tool.", default = true, type = "boolean"})
+    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"}})
     if not is_plat("macosx") then
-        add_configs("blas", {description = "Set BLAS vendor.", default = "openblas", type = "string", values = {"mkl", "openblas"}})
+        add_configs("distributed", {description = "Enable distributed support.", default = false, type = "boolean"})
     end
 
     add_deps("cmake")
-    add_deps("python 3.x", {kind = "binary", system = false})
-    add_deps("libuv")
-    add_deps("cuda", {optional = true, configs = {utils = {"nvrtc", "cudnn", "cufft", "curand", "cublas", "cudart_static"}}})
-    add_deps("nvtx", {optional = true, system = true})
+    add_deps("python 3.x", {kind = "binary"})
+
     add_includedirs("include")
     add_includedirs("include/torch/csrc/api/include")
-
     if is_plat("linux") then
         add_syslinks("rt")
     end
@@ -40,6 +41,13 @@ package("libtorch")
         if package:config("ninja") then
             package:add("deps", "ninja")
         end
+        if package:config("cuda") then
+            package:add("deps", "cuda", {configs = {utils = {"nvrtc", "cudnn", "cufft", "curand", "cublas", "cudart_static"}}})
+            package:add("deps", "nvtx")
+        end
+        if package:config("distributed") then
+            package:add("deps", "libuv")
+        end
         if not package:is_plat("macosx") and package:config("blas") then
             package:add("deps", package:config("blas"))
         end
@@ -56,13 +64,12 @@ package("libtorch")
         end
 
         -- tackle link flags
-        local has_cuda = package:dep("cuda"):exists() and package:dep("nvtx"):exists()
         local libnames = {"torch", "torch_cpu"}
-        if has_cuda then
+        if package:config("cuda") then
             table.insert(libnames, "torch_cuda")
         end
         table.insert(libnames, "c10")
-        if has_cuda then
+        if package:config("cuda") then
             table.insert(libnames, "c10_cuda")
         end
         local suffix = ""
@@ -82,11 +89,10 @@ 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"}) 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", "mkldnn", "sleef", "asmjit", "fmt", "kineto"}) do
                 package:add("links", lib)
             end
         end
-        package:add("links", "kineto")
 
         -- some patches to the third-party cmake files
         io.replace("third_party/fbgemm/CMakeLists.txt", "PRIVATE FBGEMM_STATIC", "PUBLIC FBGEMM_STATIC", {plain = true})
@@ -97,7 +103,9 @@ package("libtorch")
 
         -- prepare python
         os.vrun("python -m pip install typing_extensions pyyaml")
-        local configs = {"-DUSE_MPI=OFF", "-DCMAKE_INSTALL_LIBDIR=lib"}
+        local configs = {"-DUSE_MPI=OFF",
+                         "-DCMAKE_INSTALL_LIBDIR=lib",
+                         "-DATEN_NO_TEST=ON"}
         if package:config("python") then
             table.insert(configs, "-DBUILD_PYTHON=ON")
             os.vrun("python -m pip install numpy")
@@ -116,11 +124,17 @@ package("libtorch")
             elseif package:config("blas") == "openblas" then
                 table.insert(configs, "-DBLAS=OpenBLAS")
                 envs.OpenBLAS_HOME = package:dep("openblas"):installdir()
+            elseif package:config("blas") == "eigen" then
+                table.insert(configs, "-DBLAS=Eigen")
             end
         end
-        envs.libuv_ROOT = package:dep("libuv"):installdir()
+        if package:config("distributed") then
+            envs.libuv_ROOT = package:dep("libuv"):installdir()
+        end
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        table.insert(configs, "-DUSE_CUDA=" .. (package:config("cuda") and "ON" or "OFF"))
+        table.insert(configs, "-DUSE_DISTRIBUTED=" .. (package:config("distributed") and "ON" or "OFF"))
         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

+ 8 - 5
packages/l/libuv/xmake.lua

@@ -6,6 +6,7 @@ package("libuv")
 
     set_urls("https://github.com/libuv/libuv/archive/$(version).zip",
              "https://github.com/libuv/libuv.git")
+    add_versions("v1.44.1", "d233a9c522a9f4afec47b0d12f302d93d114a9e3ea104150e65f55fd931518e6")
     add_versions("v1.42.0", "031130768b25ae18c4b9d4a94ba7734e2072b11c6fce3e554612c516c3241402")
     add_versions("v1.41.0", "cb89a8b9f686c5ccf7ed09a9e0ece151a73ebebc17af3813159c335b02181794")
     add_versions("v1.40.0", "61366e30d8484197dc9e4a94dbd98a0ba52fb55cb6c6d991af1f3701b10f322b")
@@ -39,19 +40,21 @@ package("libuv")
         if package:config("shared") then
             package:add("defines", "USING_UV_SHARED")
         end
-        if package:version():ge("1.40.0") then
+        if package:version():ge("1.40") and package:version():lt("1.44") then
             package:add("linkdirs", path.join("lib", package:debug() and "Debug" or "Release"))
         end
     end)
 
     on_install("windows", function (package)
-        local configs = {}
+        local configs = {"-DLIBUV_BUILD_TESTS=OFF", "-DLIBUV_BUILD_BENCH=OFF"}
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
         import("package.tools.cmake").install(package, configs)
-        os.cp("include", package:installdir())
+        if package:version():lt("1.40") then
+            os.cp("include", package:installdir())
+        end
     end)
 
-    on_install("macosx", "linux", "iphoneos", "android@linux,macosx", "mingw@linux,macosx", function (package)
+    on_install("macosx", "linux", "android@linux,macosx", "mingw@linux,macosx", function (package)
         local configs = {}
         if package:config("shared") then
             table.insert(configs, "--enable-shared=yes")
@@ -61,7 +64,7 @@ package("libuv")
         if package:config("pic") ~= false then
             table.insert(configs, "--with-pic")
         end
-        if package:version():ge("1.40.0") and package:is_plat("iphoneos") then
+        if package:is_plat("iphoneos") and package:version():ge("1.40") and package:version():lt("1.44") then
             -- fix CoreFoundation type definition
             io.replace("src/unix/darwin.c", "!TARGET_OS_IPHONE", "1", {plain = true})
         end