Skip to content

Commit

Permalink
Caching kernel_bundle after create_program_from_spirv()
Browse files Browse the repository at this point in the history
  • Loading branch information
chudur-budur committed Feb 2, 2023
1 parent aa4eb5b commit a06f8f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- id: blacken-docs
additional_dependencies: [black==22.10]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
Expand Down
29 changes: 24 additions & 5 deletions numba_dpex/core/kernel_interface/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def __init__(
capacity=config.CACHE_SIZE,
pyfunc=self.pyfunc,
)
self._kernel_bundle_cache = LRUCache(
name="KernelBundleCache",
capacity=config.CACHE_SIZE,
pyfunc=self.pyfunc,
)
else:
self._cache = NullCache()
self._cache_hits = 0
Expand Down Expand Up @@ -587,6 +592,7 @@ def __call__(self, *args):
# redundant. We should avoid these checks for the specialized case.
exec_queue = self._determine_kernel_launch_queue(args, argtypes)
backend = exec_queue.backend
device = exec_queue.sycl_device

if exec_queue.backend not in [
dpctl.backend_type.opencl,
Expand Down Expand Up @@ -626,12 +632,25 @@ def __call__(self, *args):
cache=self._cache,
)

# create a sycl::KernelBundle
kernel_bundle = dpctl_prog.create_program_from_spirv(
exec_queue,
device_driver_ir_module,
" ".join(self._create_sycl_kernel_bundle_flags),
kernel_bundle_key = build_key(
tuple(argtypes),
self.pyfunc,
dpex_kernel_target.target_context.codegen(),
backend=backend,
device_type=device.device_type,
)

kernel_bundle = self._kernel_bundle_cache.get(kernel_bundle_key)

if kernel_bundle is None:
# create a sycl::KernelBundle
kernel_bundle = dpctl_prog.create_program_from_spirv(
exec_queue,
device_driver_ir_module,
" ".join(self._create_sycl_kernel_bundle_flags),
)
self._kernel_bundle_cache.put(kernel_bundle_key, kernel_bundle)

# get the sycl::kernel
sycl_kernel = kernel_bundle.get_sycl_kernel(kernel_module_name)

Expand Down
4 changes: 2 additions & 2 deletions numba_dpex/tests/test_device_array_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def data_parallel_sum(a, b, c):


@skip_no_opencl_cpu
class TestArrayArgsGPU:
class TestArrayArgsCPU:
def test_device_array_args_cpu(self):
c = np.ones_like(a)

Expand All @@ -37,7 +37,7 @@ def test_device_array_args_cpu(self):


@skip_no_opencl_gpu
class TestArrayArgsCPU:
class TestArrayArgsGPU:
def test_device_array_args_gpu(self):
c = np.ones_like(a)

Expand Down

0 comments on commit a06f8f0

Please sign in to comment.