Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/triton/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ def raise_(err):
self.module, self.function, self.n_regs, self.n_spills, self.n_max_threads = driver.active.utils.load_binary(
self.name, self.kernel, self.metadata.shared, self.metadata.build_flags,
not self.metadata.generate_native_code, device)
# PyTorch could use the updated build flags in load binary.
if hasattr(driver.active.utils, "get_last_selected_build_flags"):
new_build_flags = driver.active.utils.get_last_selected_build_flags()
if new_build_flags != self.metadata.build_flags:
self.metadata = self.metadata._replace(build_flags=new_build_flags)

if hasattr(self.metadata, "threads_per_warp"):
warp_size = self.metadata.threads_per_warp
else:
Expand Down
8 changes: 7 additions & 1 deletion third_party/intel/backend/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ sycl::context get_default_context(const sycl::device &sycl_device) {
#endif
}

static BuildFlags last_build_flag("");

extern "C" EXPORT_FUNC PyObject *get_last_selected_build_flags() {
return Py_BuildValue("s", last_build_flag().data());
}

extern "C" EXPORT_FUNC PyObject *load_binary(PyObject *args) {
const char *name, *build_flags_ptr;
int shared;
Expand Down Expand Up @@ -309,7 +315,7 @@ extern "C" EXPORT_FUNC PyObject *load_binary(PyObject *args) {
PyCapsule_New(reinterpret_cast<void *>(fun), "kernel", freeKernel);
auto kernel_bundle_py = PyCapsule_New(reinterpret_cast<void *>(mod),
"kernel_bundle", freeKernelBundle);

last_build_flag = build_flags;
return Py_BuildValue("(OOiii)", kernel_bundle_py, kernel_py, n_regs,
n_spills, n_max_threads);

Expand Down
5 changes: 4 additions & 1 deletion third_party/intel/backend/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@ def __init__(self, cache_path: str):
self.shared_library.get_device_properties.argtypes = (ctypes.c_int, )
self.shared_library.has_opencl_extension.restype = ctypes.py_object
self.shared_library.has_opencl_extension.argtypes = (ctypes.c_int, ctypes.c_char_p)
self.shared_library.get_last_selected_build_flags.restype = ctypes.py_object

def __getattribute__(self, name):
if name in ("get_device_properties", "init_devices", "wait_on_sycl_queue", "has_opencl_extension"):
if name in ("get_device_properties", "init_devices", "wait_on_sycl_queue", "has_opencl_extension",
"get_last_selected_build_flags"):
shared_library = super().__getattribute__("shared_library")
return getattr(shared_library, name)

Expand Down Expand Up @@ -318,6 +320,7 @@ def __init__(self):
self.device_count = mod.init_devices(self.get_sycl_queue())
self.wait_on_sycl_queue = mod.wait_on_sycl_queue
self.has_opencl_extension = mod.has_opencl_extension
self.get_last_selected_build_flags = mod.get_last_selected_build_flags

def get_current_device(self):
import torch
Expand Down
Loading