Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Implement compute-follows-data programming model [kernel API] - #598

Merged
PokhodenkoSA merged 42 commits into
IntelPython:mainfrom
reazulhoque:compute_follows_data_kernel
Dec 10, 2021
Merged

PokhodenkoSA merged 42 commits into
IntelPython:mainfrom
reazulhoque:compute_follows_data_kernel

Conversation

@reazulhoque

Copy link
Copy Markdown
Contributor

This PR introduces compute follows data for kernel.

The spec can be found here: https://github.com/IntelPython/DPPY-Spec/blob/compute-follows-data/compute_follows_data.md.

Comment thread numba_dppy/compiler.py Outdated
def _raise_datatype_mixed_error(argtypes):
error_message = (
"Datatypes of array passed to @numba_dppy.kernel "
"has to be uniform. Passed datatypes: %s" % str(argtypes)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message can be improved. What does "to be uniform" imply?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Please resolve if the changes are satisfactory.

Comment thread numba_dppy/compiler.py Outdated
"""
return tuple([self.typingctx.resolve_argument_type(a) for a in args])

def _datatype_uniform(self, argtypes):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please think of a better name. The work "uniform" does not convey much information.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Please resolve if the changes are satisfactory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said somewhere in other place here about this function - it breaks Single-responsibility principle. It have 2 responsibilities and you will eventually extract one of them:

  1. Return one of uniformed array types
  2. Check if array types are uniform

Comment thread numba_dppy/compiler.py Resolved
Comment thread numba_dppy/compiler.py Outdated
if type(array_type) == USMNdArrayType:
if dpctl.is_in_device_context():
raise ValueError(
"Compute will follow data! Please do not use context manager "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a warning instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly warning should show the location in code somehow.

Comment thread numba_dppy/compiler.py Resolved
Comment thread numba_dppy/compiler.py Outdated

current_queue = dpctl.utils.get_execution_queue(queues)
if current_queue is None:
raise ValueError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will prefer us raising a specialized Error (say IndeterminateExecutionQueueError) instead of a ValueError.

Comment thread numba_dppy/compiler.py Outdated
"create dpctl.tensor.usm_ndarray with equivalent SYCL queue."
)

if current_queue is None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rename current_queue to selected_queue or something more relevant. Especially as we move to the new model the notion of current queue is going away.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compute_queue, target_queue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Please resolve if the changes are satisfactory.

Comment thread numba_dppy/compiler.py Resolved
Comment thread numba_dppy/compiler.py Resolved
Comment thread numba_dppy/compiler.py Resolved
buffer_ctor_kwargs={"queue": queue},
)

sum_kernel[global_size, local_size](da, db, dc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test that computations was performed on specific queue?

@reazulhoque reazulhoque Oct 25, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I do not know of any such mechanism.

@oleksandr-pavlyk Do you happen to have any idea?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the queue has enable_profiling property, one can use dpctl.SyclTimer to check that device timer is sufficiently large. Otherwise, we need to employ profiling tools pti-gpu.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take we do not have a straight-forward way to check if computation was performed on a specific queue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It opens a very important question that has been brought up by customers as well. Numba-dppy should provide a way for users to determine where execution occurred. I will look into pti-gpu.


expected = a + b

assert np.array_equal(got, expected)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking results is not what should be tested. Queue selected for computation should be tested.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

buffer_ctor_kwargs={"queue": queue},
)

with pytest.raises(TypeError):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better to test that TypeError contains message related to compute follows data.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Please resolve if the changes are satisfactory.

buffer_ctor_kwargs={"queue": queue},
)

with pytest.raises(ValueError):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to test that ValueError contains message specific to compute follows data.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Please resolve if the changes are satisfactory.

buffer_ctor_kwargs={"queue": queue1},
)

with pytest.raises(ValueError):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to test ValueError with specific message about compute follows data.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Please resolve if the changes are satisfactory.

Comment thread conda-recipe/meta.yaml Outdated
- cython
- numba 0.54*|0.55*
- dpctl 0.10*|0.11*
- dpctl 0.11*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid these hard pinnings. Can we use >= 0.11 instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can not. It cause problems when dpctl 0.12 will appear and will be incompatible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better we release patch if it will be compatible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better we release a patch if it is incompatible. We organize development of dpctl to ensure that necessary changes in dependent projects are done concurrently

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a developer I want to have control whether to use new unstable dpctl or not to use.

@PokhodenkoSA PokhodenkoSA Nov 18, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to use wider range for dependencies. But then we have to control which package use for CI in different way.
I.e. conda_build_confgi.yaml.
I agree that conda recipe should be with wide range. An we can restrict some dependency versions only for releasing as @oleksandr-pavlyk said. But we usually work with latest dpctl version and it is not always stable.
I want to have a tool to control which stable version of dpctl to use for checking code changes in numba-dppy (which are not related to dpctl) and which potentially unstable version to use for checking that numba-dppy compatible with latest dpctl. It should be 2 separate CI branches.
I agree that configuring it via conda recipe is not ok.

@PokhodenkoSA PokhodenkoSA Nov 18, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it is not clear for me how and when we understand when we should change >=0.11 to >=0.12.
If we always test with latest dpctl we are not controlling how numba-dppy works with previous version. We should know "is it backward compatible yet or no?".
I suppose there should be separate test environments in CI.

Comment thread CHANGELOG.md Resolved
In the CFD style of programming kernels, the execution queue is determined based on the input arguments passed to a kernel function. Currently, numba-dppy's kernel API only supports array arguments that provide the :code:`__sycl_usm_array_interface__` (SUAI) attribute for CFD style programming. The SUAI attribute encodes the queue where the array was defined.


We also allow passing arrays and data types that do not provide SUAI. For such cases, programmers need to specify the queue using the :code:`dpctl.device_context` context manager. Do note that the use of :code:`dpctl.device_context` is deprecated and slotted for removal in some future release.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do note that the use of :code:dpctl.device_context is deprecated and slotted for removal in some future release.

Better to format as note.

Comment thread CHANGELOG.md Resolved

@PokhodenkoSA PokhodenkoSA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok to merge it after small polishing.

Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
@PokhodenkoSA
PokhodenkoSA merged commit 9649878 into IntelPython:main Dec 10, 2021
github-actions Bot pushed a commit that referenced this pull request Dec 10, 2021
* Initial test and check for data uniformity
* Add equivalent queue check and context_manager check
* Add equivalent test from dpctl
* Update Documentation, CHANGELOG and add example
* Use as_usm_memory for receiving sycl_queue
* Update dpctl 0.12
* dpctl 0.12 in environment.yml
* Add dpctl_support.py with dpctl_version
* Make code compatible with dpctl 0.11

Co-authored-by: Sergey Pokhodenko <pokhodenko.s.a@gmail.com> 9649878
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request kernel API About @numba_dpex.kernel decorator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants