Skip to content

Commit

Permalink
bazel test //tensorrt/test:tensorrt_mlir_dialect_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zezhang committed Oct 21, 2024
1 parent 9f12bef commit 2bf0785
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 8 deletions.
13 changes: 13 additions & 0 deletions mlir-tensorrt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,19 @@ cc_binary(
],
)

cc_binary(
name = "tensorrt-opt",
srcs = ["tensorrt/tensorrt-opt/tensorrt-opt.cpp"],
copts = [
"-DMLIR_TRT_TARGET_TENSORRT",
],
linkopts = ["-Wl,-rpath,/opt/src/mlir-tensorrt/bazel-mlir-tensorrt/external/tensorrt10_x86/targets/x86_64-linux-gnu/lib"],
deps = [
":TensorRTRegistration",
"@llvm-project//mlir:MlirOptLib",
],
)

cc_binary(
name = "mlir-tensorrt-opt",
srcs = ["tools/MlirTensorRtOpt.cpp"],
Expand Down
1 change: 0 additions & 1 deletion mlir-tensorrt/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ rules_cuda_dependencies()

register_detected_cuda_toolchains()


# -------------------------- #
# Hermetic Python Setup #
# -------------------------- #
Expand Down
4 changes: 4 additions & 0 deletions mlir-tensorrt/tensorrt/tensorrt-opt/tensorrt-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@
#include "mlir/Tools/mlir-opt/MlirOptMain.h"
#include "mlir/Transforms/Passes.h"

#ifdef MLIR_TRT_ENABLE_TESTING
namespace mlir {
void registerTestTensorKindAnalysisPass();
}
#endif // MLIR_TRT_ENABLE_TESTING

int main(int argc, char **argv) {
mlir::DialectRegistry registry;
registry.insert<mlir::tensorrt::TensorRTDialect, mlir::func::FuncDialect,
mlir::tensor::TensorDialect, mlir::arith::ArithDialect,
mlir::affine::AffineDialect, mlir::quant::QuantizationDialect,
mlir::scf::SCFDialect>();
#ifdef MLIR_TRT_ENABLE_TESTING
mlir::registerTestTensorKindAnalysisPass();
#endif // MLIR_TRT_ENABLE_TESTING
mlir::func::registerInlinerExtension(registry);
mlir::tensorrt::registerTensorRTTranslationCLOpts();
mlir::tensorrt::registerTensorRTPasses();
Expand Down
61 changes: 61 additions & 0 deletions mlir-tensorrt/tensorrt/test/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Also available under a BSD-style license. See LICENSE.

load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@llvm-project//llvm:lit_test.bzl", "lit_test")

expand_template(
name = "lit_site_cfg_py",
testonly = True,
out = "lit.site.cfg.py",
substitutions = {
"@LIT_SITE_CFG_IN_HEADER@": "# Autogenerated, do not edit.",
"\"@LLVM_TOOLS_DIR@\"": "os.path.join(os.environ['TEST_SRCDIR'], 'llvm-project', 'llvm')",
"\"@MLIR_TENSORRT_DIALECT_BINARY_DIR@\"": "os.path.join(os.environ['TEST_SRCDIR'], 'tensorrt-mlir')",
"\"@MLIR_TENSORRT_DIALECT_SOURCE_DIR@\"": "os.path.join(os.environ['TEST_SRCDIR'], 'tensorrt-mlir', 'tensorrt')",
"@MLIR_ENABLE_BINDINGS_PYTHON@": "False",
"@ENABLE_ASAN@": "False",
},
template = "lit.site.cfg.py.in",
)

# Common data used by most lit tests.
filegroup(
name = "lit_data",
testonly = True,
data = [
"lit.cfg.py",
"lit.site.cfg.py",
"@llvm-project//llvm:FileCheck",
"@llvm-project//llvm:count",
"@llvm-project//llvm:not",
],
)

[
lit_test(
name = "%s.test" % src,
srcs = [src],
data = [
"//:tensorrt-opt",
"//tensorrt/test:lit_data",
],
tags = ["tensorrt_mlir_dialect_tests"],
)
for src in glob(
[
"TensorRT/*.mlir",
],
exclude = [
# exclude MLIR_TRT_ENABLE_TESTING related tests
"TensorRT/tensor-kind-analysis.mlir",
],
)
]

test_suite(
name = "tensorrt_mlir_dialect_tests",
tags = ["tensorrt_mlir_dialect_tests"],
)
4 changes: 1 addition & 3 deletions mlir-tensorrt/tensorrt/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
# subdirectories contain auxiliary inputs for various tests in their parent
# directories.
config.excludes = ["Inputs", "Examples", "CMakeLists.txt", "README.txt", "LICENSE.txt"]
config.tensorrt_dialect_tools_dir = os.path.join(
config.tensorrt_dialect_obj_root, "bin"
)
config.tensorrt_dialect_tools_dir = os.path.join(config.tensorrt_dialect_obj_root)
config.tensorrt_dialect_libs_dir = os.path.join(config.tensorrt_dialect_obj_root, "lib")
config.substitutions.append(
("%tensorrt_dialect_libs", config.tensorrt_dialect_libs_dir)
Expand Down
2 changes: 1 addition & 1 deletion mlir-tensorrt/tensorrt/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ import lit.llvm
lit.llvm.initialize(lit_config, config)

# Let the main config do the real work.
lit_config.load_config(config, "@MLIR_TENSORRT_DIALECT_SOURCE_DIR@/test/lit.cfg.py")
lit_config.load_config(config, "@MLIR_TENSORRT_DIALECT_SOURCE_DIR@" + "/test/lit.cfg.py")
3 changes: 1 addition & 2 deletions mlir-tensorrt/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ filegroup(
name = "lit_data",
testonly = True,
data = [
"gpu_tools.py",
"lit.cfg.py",
"lit.site.cfg.py",
"gpu_tools.py",
"@llvm-project//llvm:FileCheck",
"@llvm-project//llvm:count",
"@llvm-project//llvm:not",
Expand All @@ -61,7 +61,6 @@ filegroup(
requirement("nvidia-ml-py"),
requirement("click"),
requirement("numpy"),

],
)
for src in glob([
Expand Down
2 changes: 1 addition & 1 deletion mlir-tensorrt/version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
MLIR_TENSORRT_VERSION_MAJOR = "0"
MLIR_TENSORRT_VERSION_MINOR = "1"
MLIR_TENSORRT_VERSION_PATCH = "34"
MLIR_TENSORRT_VERSION = "{}.{}.{}".format(MLIR_TENSORRT_VERSION_MAJOR, MLIR_TENSORRT_VERSION_MINOR, MLIR_TENSORRT_VERSION_PATCH)
MLIR_TENSORRT_VERSION = "{}.{}.{}".format(MLIR_TENSORRT_VERSION_MAJOR, MLIR_TENSORRT_VERSION_MINOR, MLIR_TENSORRT_VERSION_PATCH)

0 comments on commit 2bf0785

Please sign in to comment.