CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
73 lines
1.8 KiB
Python
73 lines
1.8 KiB
Python
# UNSUPPORTED: target=aarch64{{.*}}, target=arm64{{.*}}
|
|
# RUN: %PYTHON %s 2>&1 | FileCheck %s
|
|
# REQUIRES: host-supports-jit
|
|
import gc, sys, os, tempfile
|
|
from mlir.ir import *
|
|
from mlir.passmanager import *
|
|
from mlir.execution_engine import *
|
|
from mlir.runtime import *
|
|
|
|
|
|
# Log everything to stderr and flush so that we have a unified stream to match
|
|
# errors/info emitted by MLIR to stderr.
|
|
def log(*args):
|
|
print(*args, file=sys.stderr)
|
|
sys.stderr.flush()
|
|
|
|
|
|
def run(f):
|
|
log("\nTEST:", f.__name__)
|
|
f()
|
|
gc.collect()
|
|
assert Context._get_live_count() == 0
|
|
|
|
|
|
def lowerToLLVM(module):
|
|
pm = PassManager.parse(
|
|
"builtin.module(convert-func-to-llvm,reconcile-unrealized-casts)"
|
|
)
|
|
pm.run(module.operation)
|
|
return module
|
|
|
|
|
|
# Test JIT callback in global constructor
|
|
# CHECK-LABEL: TEST: testJITCallbackInGlobalCtor
|
|
def testJITCallbackInGlobalCtor():
|
|
init_cnt = 0
|
|
|
|
@ctypes.CFUNCTYPE(None)
|
|
def initCallback():
|
|
nonlocal init_cnt
|
|
init_cnt += 1
|
|
|
|
with Context():
|
|
module = Module.parse(
|
|
r"""
|
|
llvm.mlir.global_ctors ctors = [@ctor], priorities = [0 : i32], data = [#llvm.zero]
|
|
llvm.func @ctor() {
|
|
func.call @init_callback() : () -> ()
|
|
llvm.return
|
|
}
|
|
func.func private @init_callback() attributes { llvm.emit_c_interface }
|
|
"""
|
|
)
|
|
|
|
# Setup execution engine
|
|
execution_engine = ExecutionEngine(lowerToLLVM(module))
|
|
|
|
# Validate initialization hasn't run yet
|
|
assert init_cnt == 0
|
|
|
|
# # Register callback
|
|
execution_engine.register_runtime("init_callback", initCallback)
|
|
|
|
# # Initialize and verify
|
|
execution_engine.initialize()
|
|
assert init_cnt == 1
|
|
# # Second initialization should be no-op
|
|
execution_engine.initialize()
|
|
assert init_cnt == 1
|
|
|
|
|
|
run(testJITCallbackInGlobalCtor)
|