2024-10-07 14:51:52 +00:00
{
stdenv ,
fetchFromGitHub ,
cmake ,
ninja ,
llvmPackages_17 ,
cpm-cmake ,
git ,
cacert ,
python3 ,
numactl ,
sfpi ,
hwloc ,
libz ,
2024-11-19 22:32:20 +00:00
runCommand ,
libexecinfo ,
2024-11-20 20:19:43 +00:00
callPackage ,
2024-10-07 14:51:52 +00:00
} :
let
llvmPackages = llvmPackages_17 ;
depsDir = " d e p s " ;
2024-12-17 19:39:41 +00:00
version = " 0 . 5 3 . 0 " ;
2024-10-07 14:51:52 +00:00
metal-deps = metal . overrideAttrs ( previousAttrs : {
name = " t t - m e t a l - d e p s - ${ version } . t a r . g z " ;
dontBuild = true ;
2024-11-20 20:19:43 +00:00
outputHash = " s h a 2 5 6 - h h L j E s s X I D + u i P Q 3 k e x M C O V B 6 D B 9 m / e A V m f r 2 O l e G X c = " ;
2024-10-07 14:51:52 +00:00
outputHashAlgo = " s h a 2 5 6 " ;
cmakeFlags = [
" - D C P M _ D O W N L O A D _ A L L = O N "
" - D C P M _ S O U R C E _ C A C H E = ${ depsDir } "
] ;
# Infinite recursion
postUnpack = " " ;
installPhase = ''
runHook preInstall
# Prune the `.git` directories
find $ { depsDir } - name . git - type d - prune - exec rm - rf { } \ ; ;
# Build a reproducible tar, per instructions at https://reproducible-builds.org/docs/archives/
tar - - owner = 0 - - group = 0 - - numeric-owner - - format = gnu \
- - sort = name - - mtime = " @ $ S O U R C E _ D A T E _ E P O C H " \
- czf $ out \
$ { depsDir } \
runHook postInstall
'' ;
2024-11-08 19:30:03 +00:00
postInstall = " " ;
2024-10-07 14:51:52 +00:00
} ) ;
2024-11-20 20:19:43 +00:00
2024-10-07 14:51:52 +00:00
# NOTE: When changing something remember to make sure the outputHash above doesn't change, or if it changes then update it.
metal = llvmPackages . libcxxStdenv . mkDerivation {
pname = " t t - m e t a l " ;
inherit version ;
src = fetchFromGitHub {
owner = " t e n s t o r r e n t " ;
repo = " t t - m e t a l " ;
2024-12-17 19:39:41 +00:00
rev = " 1 5 4 e 6 9 9 3 a e d 7 8 2 1 3 4 4 6 c 5 9 7 3 1 e 4 1 c 3 6 1 7 d 8 3 c 1 f 1 " ;
hash = " s h a 2 5 6 - e d t l E 4 C V s T O 4 B W 0 P K h k N 0 I x d V 6 6 6 T u / Y 1 j g Z 2 E x l j e o = " ;
2024-10-07 14:51:52 +00:00
fetchSubmodules = true ;
2024-11-20 20:19:43 +00:00
fetchLFS = true ;
2024-10-07 14:51:52 +00:00
} ;
2024-11-20 20:19:43 +00:00
patches = [
./rpath.patch
] ;
2024-10-07 14:51:52 +00:00
env . NIX_CFLAGS_COMPILE = " - W n o - u n u s e d - c o m m a n d - l i n e - a r g u m e n t " ;
nativeBuildInputs = [
cmake
ninja
python3
# for cpm
git
cacert
] ;
buildInputs = [
numactl
# umd
hwloc
libz
] ;
postUnpack = ''
mkdir - p $ sourceRoot/build
tar - xf $ { metal-deps } - C $ sourceRoot/build
'' ;
postPatch = ''
cp $ { cpm-cmake } /share/cpm/CPM.cmake cmake/CPM.cmake
2024-11-20 20:19:43 +00:00
substituteInPlace tt_metal/CMakeLists.txt ttnn/CMakeLists.txt \
- - replace-fail " R E P L A C E T H I S \" " " $ o u t / l i b \" " \
- - replace-warn " R E P L A C E T H I S 1 " " $ o u t / b u i l d / l i b "
substituteInPlace tt_metal/hw/CMakeLists.txt \
- - replace-fail " F e t c h C o n t e n t _ M a k e A v a i l a b l e ( s f p i ) " " "
mkdir - p runtime
2024-12-17 19:39:41 +00:00
ln - s $ { sfpi . prebuilt } runtime/sfpi
2024-10-07 14:51:52 +00:00
'' ;
2024-11-19 22:32:20 +00:00
ARCH_NAME = " w o r m h o l e _ b 0 " ;
2024-10-07 14:51:52 +00:00
preConfigure = ''
export TT_METAL_HOME = $ ( pwd )
export PYTHONPATH = $ ( pwd )
'' ;
cmakeFlags = [
" - D C P M _ S O U R C E _ C A C H E = ${ depsDir } "
] ;
postInstall = ''
2024-11-20 20:19:43 +00:00
# Have to do this until cpp-ttnn-project-template is fixed
# ttnn-template> ninja: error: '/nix/store/-tt-metal-unstable-2024-10-04/build/lib/_ttnn.so', needed by 'sources/examples/sample_app/sample_app', missing and no known rule to make it
cp - r . . / $ out
rm - rf $ out/.cpmcache
ln - s $ out/build/deps $ out/.cpmcache
# Nix checks for references to /build/source so these should be different but not a different size to prevent corruption
find " $ o u t " - type f - print0 | while IFS = read - r - d $ ' \ 0 ' f ; do
sed - i " s | / b u i l d / s o u r c e | / s u i l d / s o u r c e | g " " $ f "
sed - i ' s | $ ORIGIN/build/lib : | $ ORIGIN/suild/lib : | g' " $ f "
2024-11-19 22:32:20 +00:00
done
2024-10-07 14:51:52 +00:00
'' ;
2024-11-20 20:19:43 +00:00
dontPatchELF = true ;
dontStrip = true ;
2024-10-07 14:51:52 +00:00
passthru = {
inherit metal-deps ;
2024-11-19 22:32:20 +00:00
tests = {
2024-11-20 20:19:43 +00:00
template = callPackage ./ttnn-template.nix { inherit metal ; } ;
2024-11-19 22:32:20 +00:00
} ;
2024-10-07 14:51:52 +00:00
} ;
} ;
in
metal