Skip to content

Move usm_ndarray into dpctl_ext.tensor#2807

Open
vlad-perevezentsev wants to merge 272 commits intoinclude-dpctl-tensorfrom
move_usm_ndarray
Open

Move usm_ndarray into dpctl_ext.tensor#2807
vlad-perevezentsev wants to merge 272 commits intoinclude-dpctl-tensorfrom
move_usm_ndarray

Conversation

@vlad-perevezentsev
Copy link
Copy Markdown
Contributor

@vlad-perevezentsev vlad-perevezentsev commented Mar 6, 2026

This PR proposes to migrate the tensor interface (usm_ndarray, dlpack, flags) into dpctl_ext/tensor making dpnp independent of dpctl's tensor module.

Updates:

  • Introduce dpctl_ext_capi.h
  • Implement a clean CMake interface library DpctlExtCAPI to properly propagate generated headers to consumers
  • Update remaining imports from dpctl.tensor to dpctl_ext.tensor
  • Link all backend extensions against DpctlExtCAPI to ensure consistent access to the C-API
  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

@ndgrigorian
Copy link
Copy Markdown
Collaborator

@antonwolfy @vlad-perevezentsev
A thought but should we consider flattening the directory structure? Since currently it's
dpnp -> dpctl_ext -> tensor (actual files...)

Maybe could we flatten to something like dpnp -> tensor (or dpctl_ext)

Base automatically changed from finalize_functional_migration to include-dpctl-tensor March 19, 2026 14:53
@antonwolfy
Copy link
Copy Markdown
Contributor

@antonwolfy @vlad-perevezentsev A thought but should we consider flattening the directory structure? Since currently it's dpnp -> dpctl_ext -> tensor (actual files...)

Maybe could we flatten to something like dpnp -> tensor (or dpctl_ext)

dpnp.tensor sounds reasonable as for me.

@antonwolfy
Copy link
Copy Markdown
Contributor

Based on warning report seems we still using import dpnp.tensor somewhere in code or tests.
Is it intentional?

pybind11_add_module(${python_module_name} MODULE ${_module_src})
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})

target_link_libraries(${python_module_name} PRIVATE DpctlExtCAPI)
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.

Why do we need that and how it worked previously without linking with dpctl lib?

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.

Previously dpnp4pybind11.hpp included dpctl_capi.h from the external dpctl package which was found via ${Dpctl_INCLUDE_DIRS} set by find_package(Dpctl).

Now dpnp4pybind11.hpp includes dpctl_ext_capi.h which is an internal header,and without linking to DpctlExtCAPI I got an error

dpnp4pybind11.hpp:41:10: fatal error: 'dpctl_ext_capi.h' file not found
   41 | #include "dpctl_ext_capi.h"

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.

But the error is about include, not about linkage.

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.

This logic has been removed in #2830 so I do not see the point in fixing it here

In any case DpctlExtCAPI is an interface library that collects include paths and build dependencies , no actual linking takes place, just only handles build order and header locations

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 comment was about target_link_libraries usage, see docs:

Specify libraries or flags to use when linking a given target and/or its dependents.

Btw, I'm fine to resolve that in the follow-up PR.

endif()

add_subdirectory(dpnp)
# DpctlExtCAPI: Interface library for dpctl_ext C-API
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.

Is it a temporary approach, or do we need to define interface lib even when it will be exposed by dpctl when the migration is completed?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's a design decision either way: dpctl exposed PyUSMArrayObject for numba-dpex's sake. So this way, usm_ndarray would be exposed to C-API and could be interacted with from C code conveniently.

It could be removed, in which case, the api methods like i.e., cdef api char* UsmNDArray_GetData could also be removed (barring causing any problems in the dpctl_ext).

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 don't think we need to migrate the code, which will not be used by someone, I'd propose to drop that.
In any case we will able to port that in the future if someone will be interesting in.

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.

The PR removing С-API logic has been pushed in #2830
Please check if I have implemented your idea correctly

@@ -0,0 +1,7 @@
# DLPack header

The header `dlpack.h` downloaded from `https://github.com/dmlc/dlpack.git` remote at tag v1.0rc commit [`62100c1`](https://github.com/dmlc/dlpack/commit/62100c123144ae7a80061f4220be2dbd3cbaefc7).
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 believe we are using the newer tag than v1.0rc

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 have updated README.md and dlapck.h to v1.3
thank you!

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.

are you sure we support 1.3 version of DLPack?

import math
import operator

import dpctl.tensor as dpt
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 still have from dpctl.tensor interface in some dpnp comments

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.

All TODO comments have been removed in #2829
The remaining comments and docstrings containing dpctl.tensor will be updated in the following PR

pybind11_add_module(${python_module_name} MODULE ${_module_src})
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})

target_link_libraries(${python_module_name} PRIVATE DpctlExtCAPI)
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 comment was about target_link_libraries usage, see docs:

Specify libraries or flags to use when linking a given target and/or its dependents.

Btw, I'm fine to resolve that in the follow-up PR.

# pylint: disable=no-name-in-module
import dpnp.backend.extensions.statistics._statistics_impl as statistics_ext
from dpctl_ext.tensor._numpy_helper import normalize_axis_index
from dpnp.dpnp_utils.dpnp_utils_common import (
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.

Suggested change
from dpnp.dpnp_utils.dpnp_utils_common import (
from .dpnp_utils.dpnp_utils_common import (

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.

Updated
Thank you

with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
from dpctl.tensor import __array_api_version__, DLDeviceType
from dpctl_ext.tensor import __array_api_version__, DLDeviceType
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.

TODO comment is missing

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 have added it
Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants