Skip to content

Commit c9893d7

Browse files
committed
[MLIR][test] introduce has_py_module_ml_dtypes
Some python MLIR tests require the `ml_dtypes` module which doesn't exist on Fedora for example. In order to avoid having to exclude a test we would like to mark certain tests that require `ml_dtypes` with: # REQUIRES: has_py_module_ml_dtypes We noticed that `mlir/python/requirements.txt` lists `ml_dtypes` as a requirement but when looking at the code in `mlir/python`, the only `import` is guarded: ```python try: import ml_dtypes except ModuleNotFoundError: # The third-party ml_dtypes provides some optional low precision data-types for NumPy. ml_dtypes = None ``` This makes `ml_dtypes` an optional dependency. Due to that reason I was thinking if using a `pyproject.toml` could be a better fit to mark dependencies as optional. But that's part of a different PR.
1 parent 171d3ed commit c9893d7

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

mlir/test/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ llvm_canonicalize_cmake_booleans(
8585
MLIR_RUN_CUDA_SM90_TESTS
8686
)
8787

88+
# Run python file to find out of ml_dtypes is supported or not.
89+
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import ml_dtypes" RESULT_VARIABLE HAS_PY_MODULE_ML_DTYPES_RET)
90+
if(NOT HAS_PY_MODULE_ML_DTYPES_RET EQUAL "0")
91+
set(HAS_PY_MODULE_ML_DTYPES 0)
92+
else()
93+
set(HAS_PY_MODULE_ML_DTYPES 1)
94+
endif()
95+
unset(HAS_PY_MODULE_ML_DTYPES_RET)
96+
8897
configure_lit_site_cfg(
8998
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
9099
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py

mlir/test/lit.cfg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ def find_real_python_interpreter():
314314
else:
315315
config.available_features.add("noasserts")
316316

317+
if config.has_py_module_ml_dtypes:
318+
config.available_features.add("has_py_module_ml_dtypes")
317319

318320
def have_host_jit_feature_support(feature_name):
319321
mlir_cpu_runner_exe = lit.util.which("mlir-cpu-runner", config.mlir_tools_dir)

mlir/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config.llvm_shlib_ext = "@SHLIBEXT@"
99
config.llvm_shlib_dir = lit_config.substitute(path(r"@SHLIBDIR@"))
1010
config.python_executable = "@Python3_EXECUTABLE@"
1111
config.enable_assertions = @ENABLE_ASSERTIONS@
12+
config.has_py_module_ml_dtypes = @HAS_PY_MODULE_ML_DTYPES@
1213
config.native_target = "@LLVM_NATIVE_ARCH@"
1314
config.host_os = "@HOST_OS@"
1415
config.host_cc = "@HOST_CC@"

mlir/test/python/execution_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: env MLIR_RUNNER_UTILS=%mlir_runner_utils MLIR_C_RUNNER_UTILS=%mlir_c_runner_utils %PYTHON %s 2>&1 | FileCheck %s
2-
# REQUIRES: host-supports-jit
2+
# REQUIRES: host-supports-jit, has_py_module_ml_dtypes
33
import gc, sys, os, tempfile
44
from mlir.ir import *
55
from mlir.passmanager import *

0 commit comments

Comments
 (0)