Sfoglia il codice sorgente

update libtorch (#3728)

* update libtorch

* fix cmake

* fix pocketfft

* fix old compilers
Hoildkv 1 anno fa
parent
commit
f19e01f038

+ 12 - 0
packages/l/libtorch/patches/2.2.2/pocketfft.patch

@@ -0,0 +1,12 @@
+diff --git a/third_party/pocketfft/pocketfft_hdronly.h b/third_party/pocketfft/pocketfft_hdronly.h
+--- a/third_party/pocketfft/pocketfft_hdronly.h
++++ b/third_party/pocketfft/pocketfft_hdronly.h
+@@ -149,7 +149,7 @@ template<> struct VLEN<double> { static constexpr size_t val=2; };
+ #endif
+ #endif
+ 
+-#if __cplusplus >= 201703L
++#if defined(__linux__) && __cplusplus >= 201703L
+ inline void *aligned_alloc(size_t align, size_t size)
+   {
+   // aligned_alloc() requires that the requested size is a multiple of "align"

+ 11 - 11
packages/l/libtorch/xmake.lua

@@ -14,12 +14,14 @@ package("libtorch")
     add_versions("v1.12.1", "664058fa83f1d8eede5d66418abff6e20bd76ca8")
     add_versions("v1.12.1", "664058fa83f1d8eede5d66418abff6e20bd76ca8")
     add_versions("v2.1.0", "7bcf7da3a268b435777fe87c7794c382f444e86d")
     add_versions("v2.1.0", "7bcf7da3a268b435777fe87c7794c382f444e86d")
     add_versions("v2.1.2", "a8e7c98cb95ff97bb30a728c6b2a1ce6bff946eb")
     add_versions("v2.1.2", "a8e7c98cb95ff97bb30a728c6b2a1ce6bff946eb")
+    add_versions("v2.2.2", "39901f229520a5256505ec24782f716ee7ddc843")
 
 
-    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_patches("1.9.x", "patches/1.9.0/gcc11.patch", "4191bb3296f18f040c230d7c5364fb160871962d6278e4ae0f8bc481f27d8e4b")
+    add_patches("1.11.0", "patches/1.11.0/gcc11.patch", "1404b0bc6ce7433ecdc59d3412e3d9ed507bb5fd2cd59134a254d7d4a8d73012")
     -- Fix compile on macOS. Refer to https://github.com/pytorch/pytorch/pull/80916
     -- 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_patches("1.12.1", "patches/1.12.1/clang.patch", "cdc3e00b2fea847678b1bcc6b25a4dbd924578d8fb25d40543521a09aab2f7d4")
+    add_patches("1.12.1", "patches/1.12.1/vs2022.patch", "5a31b9772793c943ca752c92d6415293f7b3863813ca8c5eb9d92a6156afd21d")
+    add_patches("2.2.2", "patches/2.2.2/pocketfft.patch", "8b756d867fb60839dcaeb1ee0bdf4189ee95e7f5c6f3810f8cbc8f6a5fae60e9")
 
 
     add_configs("shared",   {description = "Build shared library.", default = true, type = "boolean"})
     add_configs("shared",   {description = "Build shared library.", default = true, type = "boolean"})
     add_configs("python",   {description = "Build python interface.", default = false, type = "boolean"})
     add_configs("python",   {description = "Build python interface.", default = false, type = "boolean"})
@@ -116,6 +118,7 @@ package("libtorch")
         end
         end
 
 
         -- some patches to the third-party cmake files
         -- some patches to the third-party cmake files
+        io.replace("cmake/MiscCheck.cmake", "if(UNIX)", "if(TRUE)", {plain = true})
         io.replace("third_party/fbgemm/CMakeLists.txt", "PRIVATE FBGEMM_STATIC", "PUBLIC FBGEMM_STATIC", {plain = true})
         io.replace("third_party/fbgemm/CMakeLists.txt", "PRIVATE FBGEMM_STATIC", "PUBLIC FBGEMM_STATIC", {plain = true})
         io.replace("third_party/protobuf/cmake/install.cmake", "install%(DIRECTORY.-%)", "")
         io.replace("third_party/protobuf/cmake/install.cmake", "install%(DIRECTORY.-%)", "")
         if package:is_plat("windows") then
         if package:is_plat("windows") then
@@ -129,11 +132,8 @@ package("libtorch")
         end
         end
 
 
         -- prepare python
         -- prepare python
-        if package:is_plat("windows") then
-            os.vrun("python -m pip install typing_extensions pyyaml")
-        else
-            os.vrun("python3 -m pip install typing_extensions pyyaml")
-        end
+        local python_exe = package:is_plat("windows") and "python" or "python3"
+        os.vrun(python_exe .. " -m pip install typing_extensions pyyaml")
         local configs = {"-DUSE_MPI=OFF",
         local configs = {"-DUSE_MPI=OFF",
                          "-DUSE_NUMA=OFF",
                          "-DUSE_NUMA=OFF",
                          "-DUSE_MAGMA=OFF",
                          "-DUSE_MAGMA=OFF",
@@ -141,7 +141,7 @@ package("libtorch")
                          "-DATEN_NO_TEST=ON"}
                          "-DATEN_NO_TEST=ON"}
         if package:config("python") then
         if package:config("python") then
             table.insert(configs, "-DBUILD_PYTHON=ON")
             table.insert(configs, "-DBUILD_PYTHON=ON")
-            os.vrun("python -m pip install numpy")
+            os.vrun(python_exe .. " -m pip install numpy")
         else
         else
             table.insert(configs, "-DBUILD_PYTHON=OFF")
             table.insert(configs, "-DBUILD_PYTHON=OFF")
             table.insert(configs, "-DUSE_NUMPY=OFF")
             table.insert(configs, "-DUSE_NUMPY=OFF")
@@ -171,7 +171,7 @@ package("libtorch")
         table.insert(configs, "-DUSE_DISTRIBUTED=" .. (package:config("distributed") 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, "-DUSE_SYSTEM_PYBIND11=" .. (package:config("pybind11") and "ON" or "OFF"))
         table.insert(configs, "-DBUILD_CUSTOM_PROTOBUF=" .. (package:config("protobuf-cpp") and "OFF" or "ON"))
         table.insert(configs, "-DBUILD_CUSTOM_PROTOBUF=" .. (package:config("protobuf-cpp") and "OFF" or "ON"))
-        local pythonpath, err = os.iorun("python -c \"import sys; print(sys.executable)\"")
+        local pythonpath, err = os.iorun(python_exe .. " -c \"import sys; print(sys.executable)\"")
         table.insert(configs, "-DPYTHON_EXECUTABLE=" .. pythonpath)
         table.insert(configs, "-DPYTHON_EXECUTABLE=" .. pythonpath)
         if package:is_plat("windows") then
         if package:is_plat("windows") then
             table.insert(configs, "-DCAFFE2_USE_MSVC_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
             table.insert(configs, "-DCAFFE2_USE_MSVC_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))