Skip to content

Commit

Permalink
[TS compile] Fix torch_mlir.compile
Browse files Browse the repository at this point in the history
This commit allows to use `torch_mlir.compile` that uses TorcScript
under the hood.

e.g. to verify:
```sh
python -m e2e_testing.main -c "linalg" -f "MLP_basic" -v -s
```

Also makes float comparison a litlle less strict.

Signed-off-by: Dmitrii Makarenko <[email protected]>
  • Loading branch information
Devjiu committed Mar 27, 2024
1 parent ed4b46c commit 2e2178e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion externals/llvm-project
Submodule llvm-project updated 2486 files
2 changes: 1 addition & 1 deletion externals/tpp-mlir
11 changes: 6 additions & 5 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(LinkedLibs
MLIRArmSMEToLLVMIRTranslation
MLIRArmSVEToLLVMIRTranslation
MLIRSPIRVToLLVMIRTranslation
MLIRToLLVMIRTranslationRegistration

# Dialects.
TorchMLIRTMTensorDialect
Expand All @@ -44,18 +45,18 @@ set(LinkedLibs
TPPIR
TPPPipeline
TPPTransforms
TPPTppDialect
# TPPTppDialect
TPPLinalgXTransformOps
TPPXsmmDialect
TPPCheckToLoops
TPPLinalgToFunc
TPPLinalgToTpp
# TPPLinalgToTpp
TPPLinalgToXSMM
TPPMemRefToXSMM
# TPPMemRefToXSMM
TPPPerfToFunc
TPPPerfToLoop
TPPTppToLoops
TPPTppToXSMM
# TPPTppToLoops
# TPPTppToXSMM
TPPXsmmToFunc
TPPTestLib
xsmm
Expand Down
17 changes: 9 additions & 8 deletions lib/InitAll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
#include "TPP/Dialect/Check/CheckDialect.h"
#include "TPP/Dialect/Perf/BufferizableOpInterfaceImpl.h"
#include "TPP/Dialect/Perf/PerfDialect.h"
#include "TPP/Dialect/Tpp/BufferizableOpInterfaceImpl.h"
#include "TPP/Dialect/Tpp/TppDialect.h"
// #include "TPP/Dialect/Tpp/BufferizableOpInterfaceImpl.h"
// #include "TPP/Dialect/Tpp/TppDialect.h"
#include "TPP/Dialect/Transform/LinalgXTransformOps.h"
#include "TPP/Dialect/Xsmm/XsmmDialect.h"
#include "TPP/Passes.h"
Expand All @@ -51,21 +51,22 @@ void mlir::torch::registerAllDialects(mlir::DialectRegistry &registry) {
registry.insert<mlir::torch::Torch::TorchDialect>();
registry.insert<mlir::torch::TorchConversion::TorchConversionDialect>();
registry.insert<mlir::torch::TMTensor::TMTensorDialect>();
mlir::func::registerInlinerExtension(registry);

registry.insert<mlir::tpp::TppDialect>();
// registry.insert<mlir::tpp::TppDialect>();
registry.insert<mlir::xsmm::XsmmDialect>();
registry.insert<mlir::check::CheckDialect>();
registry.insert<mlir::perf::PerfDialect>();

// ::imex::registerAllDialects(registry);
mlir::func::registerInlinerExtension(registry);

mlir::linalgx::registerTransformDialectExtension(registry);
mlir::check::registerBufferizableOpInterfaceExternalModels(registry);
mlir::perf::registerBufferizableOpInterfaceExternalModels(registry);
mlir::tpp::registerBufferizableOpInterfaceExternalModels(registry);
// mlir::tpp::registerBufferizableOpInterfaceExternalModels(registry);

// Add the following to include *all* MLIR Core dialects, or selectively
// include what you need like above. You only need to register dialects that
// will be *parsed* by the tool, not the one generated.
registerAllDialects(registry);
mlir::linalg::registerTransformDialectExtension(registry);
mlir::tensor::registerTransformDialectExtension(registry);
registerAllToLLVMIRTranslations(registry);
Expand All @@ -89,7 +90,7 @@ void mlir::torch::registerAllPasses() {
#ifdef TORCH_MLIR_ENABLE_STABLEHLO
mlir::stablehlo::registerStablehloLegalizeToLinalgPass();
#endif
::imex::registerAllPasses();
// ::imex::registerAllPasses();
mlir::tpp::registerTppCompilerPasses();
mlir::tpp::registerTestStructuralMatchers();
mlir::tpp::registerTestForToForAllRewrite();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ def _collect_shared_libs(opts: TestOptions, libs = []):
shared_libs = [_find_shared_lib(lib) for lib in libs]
if opts.use_kernels:
shared_libs.append(_find_shared_lib("libTorchMLIRKernels.so"))
if opts.use_gpu_runtime:
shared_libs.append(_find_shared_lib("liblevel-zero-runtime.so"))
if opts.use_omp:
shared_libs.append(_find_shared_lib("libiomp5.so"))
return shared_libs
Expand Down
2 changes: 1 addition & 1 deletion projects/pt1/python/torch_mlir_e2e_test/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _evaluate_outcome(self):
return self._record_failure(
f'dtype ({value.dtype}) is not equal to golden dtype ({golden.dtype})'
)
if not torch.allclose(value, golden, rtol=1e-03, atol=1e-07, equal_nan=True):
if not torch.allclose(value, golden, rtol=1e-02, atol=1e-04, equal_nan=True):
return self._record_failure(
f'value ({TensorSummary(value)}) is not close to golden value ({TensorSummary(golden)})'
)
Expand Down
3 changes: 1 addition & 2 deletions pytorch-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--trusted-host spr.x1infra.com
-f http://spr.x1infra.com/pytorch_whl_nightly_cpu/torch_nightly.html
-f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
--pre
torch==2.4.0.dev20240318
3 changes: 1 addition & 2 deletions torchvision-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--trusted-host spr.x1infra.com
-f http://spr.x1infra.com/pytorch_whl_nightly_cpu/torch_nightly.html
-f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
--pre
torchvision==0.18.0.dev20240318
9 changes: 6 additions & 3 deletions utils/build-with-imex.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ project_dir=$PWD
echo "Using project dir: ${project_dir}"

# assuming git submodule update --init was done and all the code is present
git submodule foreach --recursive git checkout .
# git submodule foreach --recursive git checkout .

pushd externals/llvm-project
git reset --hard
git checkout `cat ${project_dir}/externals/tpp-mlir/build_tools/llvm_version.txt`
popd

pushd externals/stablehlo
git reset --hard
git apply ${project_dir}/utils/token-name.patch
popd

cmake -GNinja -Bbuild \
Expand All @@ -22,7 +26,6 @@ cmake -GNinja -Bbuild \
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$PWD" \
-DLLVM_EXTERNAL_TPP_MLIR_SOURCE_DIR="$PWD/externals/tpp-mlir" \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DIMEX_ENABLE_L0_RUNTIME=ON \
-DLLVM_TARGETS_TO_BUILD=host \
externals/llvm-project/llvm

Expand Down

0 comments on commit 2e2178e

Please sign in to comment.