Skip to content

Commit d4c9fcc

Browse files
Fix compat issues with LLVM15 in numba 0.61.x (#39)
- Add patch for openmp 15.0.7 to build DeviceRTL bitcodes without opaque pointers - Cleanup code and improve diagnostic output
1 parent 90c0385 commit d4c9fcc

4 files changed

Lines changed: 26 additions & 10 deletions

File tree

setup.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,9 @@ def _build_cmake(self, ext: CMakeExtension):
121121

122122
def _env_toolchain_args(self, ext):
123123
args = []
124-
# Forward LLVM_DIR and CLANG_TOOL if provided.
124+
# Forward LLVM_DIR if provided.
125125
if os.environ.get("LLVM_DIR"):
126126
args.append(f"-DLLVM_DIR={os.environ['LLVM_DIR']}")
127-
if ext.name == "libomp":
128-
# CLANG_TOOL is used by libomp to find clang for generating the OpenMP
129-
# device runtime bitcodes.
130-
if os.environ.get("CLANG_TOOL"):
131-
args.append(f"-DCLANG_TOOL={os.environ['CLANG_TOOL']}")
132127
return args
133128

134129

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/libomptarget/DeviceRTL/CMakeLists.txt b/libomptarget/DeviceRTL/CMakeLists.txt
2+
index ce66214..04c9dd5 100644
3+
--- a/libomptarget/DeviceRTL/CMakeLists.txt
4+
+++ b/libomptarget/DeviceRTL/CMakeLists.txt
5+
@@ -127,6 +127,7 @@ set(bc_flags -c -emit-llvm -std=c++17 -fvisibility=hidden
6+
-fopenmp -fopenmp-cuda-mode
7+
-I${include_directory}
8+
-I${devicertl_base_directory}/../include
9+
+ -Xclang -no-opaque-pointers
10+
${LIBOMPTARGET_LLVM_INCLUDE_DIRS_DEVICERTL}
11+
)
12+

src/numba/openmp/libs/pass/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ find_package(LLVM REQUIRED CONFIG NO_DEFAULT_PATH PATHS
1313
${LLVM_DIR}
1414
)
1515

16-
message(STATUS "LLVM_VERSION ${LLVM_VERSION}")
16+
message(STATUS "Found LLVM version ${LLVM_VERSION}")
1717

1818
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
1919

src/numba/openmp/omp_ir.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,15 @@ def __init__(self):
122122
self.libomptarget_arch = (
123123
libpath / "libomp" / "lib" / f"libomptarget-nvptx-{self.sm}.bc"
124124
)
125-
with open(self.libomptarget_arch, "rb") as f:
126-
libomptarget_mod = ll.parse_bitcode(f.read())
125+
126+
try:
127+
with open(self.libomptarget_arch, "rb") as f:
128+
libomptarget_mod = ll.parse_bitcode(f.read())
129+
except FileNotFoundError:
130+
raise RuntimeError(
131+
f"Device RTL for architecture {self.sm} not found. Check compute capability with LLVM version {'.'.join(map(str, ll.llvm_version_info))}."
132+
)
133+
127134
## Link in device, openmp libraries.
128135
self.libs_mod.link_in(libomptarget_mod)
129136
# Initialize asm printers to codegen ptx.
@@ -1493,7 +1500,9 @@ def add_mapped_to_ins(ins, tags):
14931500
# include a branch converging variable $cp. Remove it to avoid the
14941501
# assert since the openmp region must be single-entry, single-exit.
14951502
if sys.version_info >= (3, 10) and sys.version_info < (3, 11):
1496-
assert len(target_args) == len([x for x in target_args_unordered if x != "$cp"])
1503+
assert len(target_args) == len(
1504+
[x for x in target_args_unordered if x != "$cp"]
1505+
)
14971506
else:
14981507
assert len(target_args) == len(target_args_unordered)
14991508
assert len(target_args) == len(outline_arg_typs)

0 commit comments

Comments
 (0)