gnu: Add tvm.

* gnu/packages/machine-learning.scm (tvm): New variable.
* gnu/packages/patches/tvm_fix_cpptest_build.patch: New file.
* gnu/local.mk: Register new file.

Change-Id: Icfee19fccc7cc1c9f6d5d6bb680b554d777f62d6
Signed-off-by: Nicolas Goaziou <mail@nicolasgoaziou.fr>
This commit is contained in:
Andy Tai 2025-03-05 23:35:41 -08:00 committed by Nicolas Goaziou
parent 9b50aa9bfc
commit 5adfe1b8e9
No known key found for this signature in database
GPG key ID: DA00B4F048E92F2D
3 changed files with 110 additions and 0 deletions

View file

@ -2329,6 +2329,7 @@ dist_patch_DATA = \
%D%/packages/patches/turbovnc-custom-paths.patch \
%D%/packages/patches/turbovnc-find-system-packages.patch \
%D%/packages/patches/tuxpaint-stamps-path.patch \
%D%/packages/patches/tvm_fix_cpptest_build.patch \
%D%/packages/patches/twinkle-bcg729.patch \
%D%/packages/patches/u-boot-allow-disabling-openssl.patch \
%D%/packages/patches/u-boot-nintendo-nes-serial.patch \

View file

@ -93,6 +93,7 @@
#:use-module (gnu packages image-processing)
#:use-module (gnu packages imagemagick)
#:use-module (gnu packages jupyter)
#:use-module (gnu packages libedit)
#:use-module (gnu packages libevent)
#:use-module (gnu packages libffi)
#:use-module (gnu packages linux)
@ -117,6 +118,7 @@
#:use-module (gnu packages python-xyz)
#:use-module (gnu packages rdf)
#:use-module (gnu packages regex)
#:use-module (gnu packages rocm)
#:use-module (gnu packages rpc)
#:use-module (gnu packages sdl)
#:use-module (gnu packages serialization)
@ -4630,6 +4632,95 @@ rich objects from one process to another while using the fastest transport for
the tensors contained therein.")
(license license:bsd-3))))
(define-public tvm
;; Include a bug fix post 0.19 release.
(let ((commit "d3a2ed68a42f8b51d8ab1533b62e837b9ea74b8e")
(revision "1"))
(package
(name "tvm")
(version (git-version "0.20.dev0" revision commit))
(source
(origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/apache/tvm")
(commit commit)))
(patches (search-patches "tvm_fix_cpptest_build.patch"))
(file-name (git-file-name name version))
(sha256
(base32 "0ng52i0aydljnlrkyg069838c8b311fynhy5976w74smma2m7v72"))))
(build-system cmake-build-system)
(arguments
(list
#:test-target "cpptest"
#:configure-flags
#~(list "-DUSE_OPENCL=ON"
"-DUSE_VULKAN=ON"
"-DUSE_OPENCL_ENABLE_HOST_PTR=ON"
"-DINSTALL_DEV=ON"
"-DUSE_GTEST=ON"
"-DHIDE_PRIVATE_SYMBOLS=ON" ;per upstream build instructions
"-DUSE_LLVM=llvm-config\\ --ignore-libllvm\\ --link-static"
;; per upstream build instructions
(string-append "-DDLPACK_PATH="
(assoc-ref %build-inputs "dlpack") "/include")
(string-append "-DDMLC_PATH="
(assoc-ref %build-inputs "dmlc-core")
"/include")
(string-append "-DRANG_PATH="
(assoc-ref %build-inputs "rang") "/include"))
#:phases
#~(modify-phases %standard-phases
(replace 'check
(lambda* (#:key source test-target tests? #:allow-other-keys)
(when tests?
(begin
(invoke "make" "-j"
(number->string (parallel-job-count)) test-target)
;; Disable below the actual run of the tests because
;; several fail due to platform variations (for example,
;; fp16 tests fail because not supported on CPUs).
;;
;; (chdir "..")
;; (invoke (which "bash")
;; (string-append source
;; "/tests/scripts/task_cpp_unittest.sh"))
)))))))
(inputs (list dmlc-core-next
dlpack
libedit
libxml2
llvm-19
opencl-clhpp
opencl-headers
rang
mesa
mesa-opencl
spirv-headers
spirv-tools
vulkan-headers ;TODO; now not building due to missing vta-hw
vulkan-loader
zlib
zstd))
(native-inputs (list bash-minimal
gcc-14
googletest
(module-ref (resolve-interface '(gnu packages debug))
'libbacktrace)
pkg-config
python
python-cython))
(home-page "https://tvm.apache.org/")
(synopsis
"Machine learning compiler framework for CPUs, GPUs and accelerators")
(description
"Apache TVM is a compiler stack for deep learning systems. It is
designed to close the gap between the productivity-focused deep learning
frameworks, and the performance- and efficiency-focused hardware backends.
TVM works with deep learning frameworks to provide end to end compilation to
different backends")
(license license:asl2.0))))
(define-public foxi
(let
((commit "c278588e34e535f0bb8f00df3880d26928038cad")

View file

@ -0,0 +1,18 @@
Fix build of cpptest by correcting relative include paths
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 757b0d1a8..546ecd516 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -778,6 +778,11 @@ endif()
if(GTEST_FOUND)
tvm_file_glob(GLOB_RECURSE TEST_SRCS tests/cpp/*.cc)
add_executable(cpptest ${TEST_SRCS})
+
+ # fix building cpptest if we don't use 3rdParty subtree as when building with GNU Guix
+ # allowng relative paths starting with ../../.. to point to the top of the source dir
+ target_include_directories(cpptest PRIVATE tests/cpp/runtime)
+
# include runtime files for unit testing
target_link_libraries(cpptest PRIVATE ${TVM_TEST_LIBRARY_NAME} GTest::GTest GTest::Main GTest::gmock pthread dl)
if(DEFINED LLVM_LIBS)