Skip to content

Commit 946ce93

Browse files
Move dpctl C-API imports to dpctl_ext_capi.h
1 parent 3ba741a commit 946ce93

3 files changed

Lines changed: 110 additions & 87 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,17 @@ endif()
347347
# DpctlExtCAPI: Interface library for dpctl_ext C-API
348348
# Provides access to:
349349
# 1. Public C-API headers from dpctl_ext/apis/include
350-
# 2. Generated Cython headers from the build directory
351-
#
352-
# This follows the same pattern as dpctl's DpctlCAPI interface library
350+
# 2. Generated Cython headers from a specific build subdirectory
351+
352+
# Set the specific directory for generated Cython headers
353+
set(DPCTL_EXT_GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR})
353354

354355
add_library(DpctlExtCAPI INTERFACE)
355356
target_include_directories(
356357
DpctlExtCAPI
357358
INTERFACE
358359
${CMAKE_CURRENT_SOURCE_DIR}/dpctl_ext/apis/include
359-
${CMAKE_BINARY_DIR} # For generated Cython headers
360+
${DPCTL_EXT_GENERATED_INCLUDE_DIR}
360361
)
361362

362363
add_subdirectory(dpctl_ext)
Lines changed: 94 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,106 @@
1-
//===----------- dpctl_ext_capi.h - Headers for dpctl_ext C-API -*-C++-*-===//
1+
//*****************************************************************************
2+
// Copyright (c) 2026, Intel Corporation
3+
// All rights reserved.
24
//
3-
// Data Parallel Extension for NumPy (dpnp)
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are met:
7+
// - Redistributions of source code must retain the above copyright notice,
8+
// this list of conditions and the following disclaimer.
9+
// - Redistributions in binary form must reproduce the above copyright notice,
10+
// this list of conditions and the following disclaimer in the documentation
11+
// and/or other materials provided with the distribution.
12+
// - Neither the name of the copyright holder nor the names of its contributors
13+
// may be used to endorse or promote products derived from this software
14+
// without specific prior written permission.
415
//
5-
// Copyright 2026 Intel Corporation
16+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26+
// THE POSSIBILITY OF SUCH DAMAGE.
27+
//*****************************************************************************
628
//
7-
// Licensed under the Apache License, Version 2.0 (the "License");
8-
// you may not use this file except in compliance with the License.
9-
// You may obtain a copy of the License at
10-
//
11-
// http://www.apache.org/licenses/LICENSE-2.0
12-
//
13-
// Unless required by applicable law or agreed to in writing, software
14-
// distributed under the License is distributed on an "AS IS" BASIS,
15-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
// See the License for the specific language governing permissions and
17-
// limitations under the License.
18-
//
19-
//===----------------------------------------------------------------------===//
29+
//===---------------------------------------------------------------------===//
2030
///
2131
/// \file
22-
/// This file provides access to dpctl_ext's C-API, primarily for accessing
23-
/// usm_ndarray types generated by Cython.
24-
///
25-
/// The generated Cython headers are located in the build directory at:
26-
/// ${CMAKE_BINARY_DIR}/dpctl_ext/tensor/
27-
///
28-
/// This header serves as the public API entry point and should be included
29-
/// instead of directly including the generated headers.
30-
//===----------------------------------------------------------------------===//
32+
/// This file provides access to dpctl_ext's C-API, including:
33+
/// - dpctl C-API (from external dpctl package - SYCL interface)
34+
/// - dpctl_ext tensor C-API (usm_ndarray)
35+
//===---------------------------------------------------------------------===//
3136

3237
#pragma once
3338

39+
// Include dpctl C-API headers explicitly from external dpctl package (SYCL
40+
// interface)
41+
// TODO: Once dpctl removes its tensor module and stabilizes dpctl_capi.h,
42+
// we can simplify to just: #include "dpctl_capi.h"
43+
// For now, explicit includes ensure we only get SYCL interface without tensor.
44+
45+
#include "syclinterface/dpctl_sycl_extension_interface.h"
46+
#include "syclinterface/dpctl_sycl_types.h"
47+
48+
#ifdef __cplusplus
49+
#define CYTHON_EXTERN_C extern "C"
50+
#else
51+
#define CYTHON_EXTERN_C
52+
#endif
53+
54+
#include "dpctl/_sycl_context.h"
55+
#include "dpctl/_sycl_context_api.h"
56+
#include "dpctl/_sycl_device.h"
57+
#include "dpctl/_sycl_device_api.h"
58+
#include "dpctl/_sycl_event.h"
59+
#include "dpctl/_sycl_event_api.h"
60+
#include "dpctl/_sycl_queue.h"
61+
#include "dpctl/_sycl_queue_api.h"
62+
#include "dpctl/memory/_memory.h"
63+
#include "dpctl/memory/_memory_api.h"
64+
#include "dpctl/program/_program.h"
65+
#include "dpctl/program/_program_api.h"
66+
3467
// Include the generated Cython C-API headers for usm_ndarray
3568
// These headers are generated during build and placed in the build directory
3669
#include <dpctl_ext/tensor/_usmarray.h>
3770
#include <dpctl_ext/tensor/_usmarray_api.h>
71+
72+
/*
73+
* Function to import dpctl_ext C-API and make it available.
74+
* This imports both:
75+
* - dpctl C-API (from external dpctl package - SYCL interface)
76+
* - dpctl_ext C-API (tensor interface - usm_ndarray)
77+
*
78+
* C functions can use dpctl_ext's C-API functions without linking to
79+
* shared objects defining these symbols, if they call `import_dpctl_ext()`
80+
* prior to using those symbols.
81+
*
82+
* It is declared inline to allow multiple definitions in
83+
* different translation units.
84+
*
85+
* TODO: When dpctl_ext is renamed to dpctl.tensor:
86+
* - Rename this file: dpctl_ext_capi.h → dpctl/tensor/tensor_capi.h
87+
* (Use tensor_capi.h, NOT dpctl_capi.h, to avoid conflict with external
88+
* dpctl)
89+
* - Rename this function: import_dpctl_ext() → import_dpctl_tensor()
90+
* - Include external dpctl_capi.h and simplify imports to use import_dpctl()
91+
*/
92+
static inline void import_dpctl_ext(void)
93+
{
94+
// Import dpctl SYCL interface
95+
// TODO: Once dpctl removes its tensor module and stabilizes dpctl_capi.h,
96+
// we can simplify to just: import_dpctl()
97+
import_dpctl___sycl_device();
98+
import_dpctl___sycl_context();
99+
import_dpctl___sycl_event();
100+
import_dpctl___sycl_queue();
101+
import_dpctl__memory___memory();
102+
import_dpctl__program___program();
103+
// Import dpctl_ext tensor interface
104+
import_dpctl_ext__tensor___usmarray();
105+
return;
106+
}

dpnp/backend/include/dpnp4pybind11.hpp

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,66 +28,18 @@
2828

2929
#pragma once
3030

31-
// TODO: Enable dpctl_capi.h once dpctl.tensor is removed.
32-
// Also call `import_dpctl_ext__tensor___usmarray();` right after
33-
// `import_dpctl()` (line 334) to initialize the dpctl_ext tensor C-API.
31+
// Include dpctl_ext C-API (provides unified access to both dpctl and dpctl_ext)
32+
// This includes:
33+
// - dpctl C-API (from external dpctl package - SYCL interface)
34+
// - dpctl_ext C-API (tensor interface: usm_ndarray)
3435
//
35-
// Now we include dpctl C-API headers explicitly in order to
36-
// integrate dpctl_ext tensor C-API.
37-
38-
// #include "dpctl_capi.h"
39-
40-
// clang-format off
41-
// Ordering of includes is important here. dpctl_sycl_types and
42-
// dpctl_sycl_extension_interface define types used by dpctl's Python
43-
// C-API headers.
44-
#include "syclinterface/dpctl_sycl_types.h"
45-
#include "syclinterface/dpctl_sycl_extension_interface.h"
46-
#ifdef __cplusplus
47-
#define CYTHON_EXTERN_C extern "C"
48-
#else
49-
#define CYTHON_EXTERN_C
50-
#endif
51-
#include "dpctl/_sycl_device.h"
52-
#include "dpctl/_sycl_device_api.h"
53-
#include "dpctl/_sycl_context.h"
54-
#include "dpctl/_sycl_context_api.h"
55-
#include "dpctl/_sycl_event.h"
56-
#include "dpctl/_sycl_event_api.h"
57-
#include "dpctl/_sycl_queue.h"
58-
#include "dpctl/_sycl_queue_api.h"
59-
#include "dpctl/memory/_memory.h"
60-
#include "dpctl/memory/_memory_api.h"
61-
#include "dpctl/program/_program.h"
62-
#include "dpctl/program/_program_api.h"
63-
64-
// clang-format on
65-
66-
// Include dpctl_ext C-API (provides access to usm_ndarray types)
67-
// This uses the public API header from dpctl_ext/apis/include
36+
// TODO: When dpctl_ext is renamed to dpctl.tensor:
37+
// - Update include: "dpctl_ext_capi.h" → "dpctl/tensor/tensor_capi.h"
38+
// (Use tensor_capi.h, NOT dpctl_capi.h, to avoid conflict with external
39+
// dpctl)
40+
// - Update import calls: import_dpctl_ext() → import_dpctl_tensor()
6841
#include "dpctl_ext_capi.h"
6942

70-
/*
71-
* Function to import dpctl and make C-API functions available.
72-
* C functions can use dpctl's C-API functions without linking to
73-
* shared objects defining this symbols, if they call `import_dpctl()`
74-
* prior to using those symbols.
75-
*
76-
* It is declared inline to allow multiple definitions in
77-
* different translation units
78-
*/
79-
static inline void import_dpctl(void)
80-
{
81-
import_dpctl___sycl_device();
82-
import_dpctl___sycl_context();
83-
import_dpctl___sycl_event();
84-
import_dpctl___sycl_queue();
85-
import_dpctl__memory___memory();
86-
import_dpctl_ext__tensor___usmarray();
87-
import_dpctl__program___program();
88-
return;
89-
}
90-
9143
#include <array>
9244
#include <complex>
9345
#include <cstddef> // for std::size_t for C++ linkage
@@ -341,7 +293,8 @@ class dpctl_capi
341293
// e.g. SyclDevice_GetDeviceRef, etc.
342294
// pointers to Python types, i.e. PySyclDeviceType, etc.
343295
// and exported constants, i.e. USM_ARRAY_C_CONTIGUOUS, etc.
344-
import_dpctl();
296+
// TODO: rename once dpctl_ext is renamed
297+
import_dpctl_ext(); // Imports both dpctl and dpctl_ext C-APIs
345298

346299
// Python type objects for classes implemented by dpctl
347300
this->Py_SyclDeviceType_ = &Py_SyclDeviceType;

0 commit comments

Comments
 (0)