Skip to content

Commit

Permalink
[nix] embedded pyenv to buddy-mlir sub attr
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Aug 9, 2024
1 parent 4ee121a commit 2736e68
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 49 deletions.
4 changes: 0 additions & 4 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ rec {

# DynamoCompiler doesn't support python 3.12+ yet
buddy-mlir = final.callPackage ./pkgs/buddy-mlir.nix { python3 = final.python311; };
buddy-mlir-pyenv = final.buddy-mlir.pythonModule.withPackages (ps: [
final.buddy-mlir
ps.torch
]);

fetchMillDeps = final.callPackage ./pkgs/mill-builder.nix { };
circt-full = final.callPackage ./pkgs/circt-full.nix { };
Expand Down
91 changes: 49 additions & 42 deletions nix/pkgs/buddy-mlir.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,54 @@ let
bintools = llvmPackages_17.bintools;

buddy-llvm = callPackage ./buddy-llvm.nix { inherit stdenv python3; };
in
stdenv.mkDerivation {
pname = "buddy-mlir";
version = "unstable-2024-07-18";

src = fetchFromGitHub {
owner = "buddy-compiler";
repo = "buddy-mlir";
rev = "d7d90a488ac0d6fc1e700e932f842c7b2bcad816";
hash = "sha256-MhykCa6Z7Z8PpAlNh+vMuWYEOZZDyWhtMzMnFlNbGIk=";
};
self = stdenv.mkDerivation {
pname = "buddy-mlir";
version = "unstable-2024-07-18";

src = fetchFromGitHub {
owner = "buddy-compiler";
repo = "buddy-mlir";
rev = "d7d90a488ac0d6fc1e700e932f842c7b2bcad816";
hash = "sha256-MhykCa6Z7Z8PpAlNh+vMuWYEOZZDyWhtMzMnFlNbGIk=";
};

nativeBuildInputs = [ cmake ninja bintools ];
buildInputs = [
buddy-llvm
];

cmakeFlags = [
"-DMLIR_DIR=${buddy-llvm.dev}/lib/cmake/mlir"
"-DLLVM_DIR=${buddy-llvm.dev}/lib/cmake/llvm"
"-DLLVM_MAIN_SRC_DIR=${buddy-llvm.src}/llvm"
"-DBUDDY_MLIR_ENABLE_PYTHON_PACKAGES=ON"
"-DCMAKE_BUILD_TYPE=Release"
];

nativeBuildInputs = [ cmake ninja bintools ];
buildInputs = [
buddy-llvm
];

cmakeFlags = [
"-DMLIR_DIR=${buddy-llvm.dev}/lib/cmake/mlir"
"-DLLVM_DIR=${buddy-llvm.dev}/lib/cmake/llvm"
"-DLLVM_MAIN_SRC_DIR=${buddy-llvm.src}/llvm"
"-DBUDDY_MLIR_ENABLE_PYTHON_PACKAGES=ON"
"-DCMAKE_BUILD_TYPE=Release"
];

# No need to do check, and it also takes too much time to finish.
doCheck = false;

# Here we concatenate the LLVM and Buddy python module into one directory for easier import
postFixup = ''
mkdir -p $out/lib/python${python3.pythonVersion}/site-packages
cp -vr $out/python_packages/buddy $out/lib/python${python3.pythonVersion}/site-packages/
cp -vr ${buddy-llvm}/python_packages/mlir_core/mlir $out/lib/python${python3.pythonVersion}/site-packages/
'';

passthru = {
llvm = buddy-llvm;

# Below three fields are black magic that allow site-packages automatically imported with nixpkgs hooks
pythonModule = python3;
pythonPath = [ ];
requiredPythonModules = [ ];
# No need to do check, and it also takes too much time to finish.
doCheck = false;

# Here we concatenate the LLVM and Buddy python module into one directory for easier import
postFixup = ''
mkdir -p $out/lib/python${python3.pythonVersion}/site-packages
cp -vr $out/python_packages/buddy $out/lib/python${python3.pythonVersion}/site-packages/
cp -vr ${buddy-llvm}/python_packages/mlir_core/mlir $out/lib/python${python3.pythonVersion}/site-packages/
'';

passthru = {
llvm = buddy-llvm;

# Below three fields are black magic that allow site-packages automatically imported with nixpkgs hooks
pythonModule = python3;
pythonPath = [ ];
requiredPythonModules = [ ];

# nix run buddy-mlir.pyenv to start a python with PyTorch/LLVM MLIR/Buddy Frontend support
pyenv = python3.withPackages (ps: [
self
ps.torch
]);
};
};
}
in
self
2 changes: 1 addition & 1 deletion tests/pytorch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ nix build '.#t1.blastoise.ip.cases.pytorch.demo.emu-result.with-trace' -L
* How to debug the PyTorch code

```bash
nix run '.#buddy-mlir-pyenv' -- demo.py
nix run '.#buddy-mlir.pyenv' -- demo.py
```

* How to run buddy compiler tools manually
Expand Down
3 changes: 1 addition & 2 deletions tests/pytorch/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ lib
, linkerScript
, buddy-mlir
, buddy-mlir-pyenv
, makeBuilder
, findAndBuild
, getTestRequiredFeatures
Expand Down Expand Up @@ -29,7 +28,7 @@ let

featuresRequired = getTestRequiredFeatures sourcePath;

nativeBuildInputs = [ buddy-mlir-pyenv buddy-mlir ];
nativeBuildInputs = [ buddy-mlir.pyenv buddy-mlir ];

pythonArgs = buddyBuildConfig.pythonArgs or [ ];
buddyTranslateArgs = buddyBuildConfig.buddyTranslateArgs or defaultBuddyTranslateArgs;
Expand Down

0 comments on commit 2736e68

Please sign in to comment.