Skip to content

Commit

Permalink
Fix nvvm.compile_program() failure for CUDA version 12.0
Browse files Browse the repository at this point in the history
The original datalayout lacked explicit alignment and size definitions for i1, i8, i16, f32, f64, v64, and v128.

The missing types are crucial for LLVM-based compilation in CUDA 12.0.

Later CUDA versions are more forgiving, but 12.0 enforces a stricter layout. The stricter layout should resolve the issue for CUDA 12.0
without breaking compatibility with later versions.
  • Loading branch information
rwgk committed Feb 4, 2025
1 parent cb991d7 commit ee149f0
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions cuda_bindings/tests/test_nvvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from cuda.bindings import nvvm

MINIMAL_NVVMIR = b"""\
target datalayout = "e-p:64:64:64-i64:64:64:64-i128:128:128:128-v16:16:16:16-v32:32:32:32-n16:32:64"
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
target triple = "nvptx64-nvidia-cuda"
define void @kernel() {
Expand All @@ -20,7 +21,7 @@
!nvvmir.version = !{!1}
!1 = !{i32 2, i32 0, i32 3, i32 1}
"""
""" # noqa: E501


def test_nvvm_version():
Expand Down Expand Up @@ -112,12 +113,18 @@ def test_with_minimal_nnvm_ir():
prog = nvvm.create_program()
try:
nvvm.add_module_to_program(prog, MINIMAL_NVVMIR, len(MINIMAL_NVVMIR), "FileNameHere.ll")
nvvm.compile_program(prog, 0, [])
log_size = nvvm.get_program_log_size(prog)
assert log_size == 1
buffer = bytearray(log_size)
nvvm.get_program_log(prog, buffer)
assert buffer == b"\x00"
try:
nvvm.compile_program(prog, 0, [])
except nvvm.nvvmError as e:
buffer = bytearray(nvvm.get_program_log_size(prog))
nvvm.get_program_log(prog, buffer)
raise RuntimeError(buffer.decode(errors="backslashreplace")) from e
else:
log_size = nvvm.get_program_log_size(prog)
assert log_size == 1
buffer = bytearray(log_size)
nvvm.get_program_log(prog, buffer)
assert buffer == b"\x00"
result_size = nvvm.get_compiled_result_size(prog)
buffer = bytearray(result_size)
nvvm.get_compiled_result(prog, buffer)
Expand Down

0 comments on commit ee149f0

Please sign in to comment.