Skip to content

Commit 4d6242e

Browse files
authored
Merge 1d7fadc into cb31797
2 parents cb31797 + 1d7fadc commit 4d6242e

File tree

12 files changed

+316
-155
lines changed

12 files changed

+316
-155
lines changed

CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,62 @@ find_package(Dpctl REQUIRED)
6767
message(STATUS "Dpctl_INCLUDE_DIR=" ${Dpctl_INCLUDE_DIR})
6868
message(STATUS "Dpctl_TENSOR_INCLUDE_DIR=" ${Dpctl_TENSOR_INCLUDE_DIR})
6969

70+
option(DPNP_TARGET_CUDA
71+
"Build DPNP to target CUDA devices"
72+
OFF
73+
)
74+
option(DPNP_USE_ONEMKL_INTERFACES
75+
"Build DPNP with oneMKL Interfaces"
76+
OFF
77+
)
78+
set(_dpnp_sycl_targets)
79+
set(_use_onemkl_interfaces_cuda OFF)
80+
if ("x${DPNP_SYCL_TARGETS}" STREQUAL "x")
81+
if(DPNP_TARGET_CUDA)
82+
set(_dpnp_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
83+
set(_use_onemkl_interfaces_cuda ON)
84+
else()
85+
if(DEFINED ENV{DPNP_TARGET_CUDA})
86+
set(_dpnp_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
87+
set(_use_onemkl_interfaces_cuda ON)
88+
endif()
89+
endif()
90+
else()
91+
set(_dpnp_sycl_targets ${DPNP_SYCL_TARGETS})
92+
endif()
93+
94+
if(_dpnp_sycl_targets)
95+
message(STATUS "Compiling for -fsycl-targets=${_dpnp_sycl_targets}")
96+
endif()
97+
98+
set(_use_onemkl_interfaces OFF)
99+
if(DPNP_USE_ONEMKL_INTERFACES)
100+
set(_use_onemkl_interfaces ON)
101+
else()
102+
if(DEFINED ENV{DPNP_USE_ONEMKL_INTERFACES})
103+
set(_use_onemkl_interfaces ON)
104+
endif()
105+
endif()
106+
107+
if(_use_onemkl_interfaces)
108+
set(BUILD_FUNCTIONAL_TESTS False)
109+
set(BUILD_EXAMPLES False)
110+
if(_use_onemkl_interfaces_cuda)
111+
# set(ENABLE_CUBLAS_BACKEND True)
112+
set(ENABLE_CUSOLVER_BACKEND True)
113+
set(ENABLE_CUFFT_BACKEND True)
114+
# set(ENABLE_CURAND_BACKEND True)
115+
set(ENABLE_MKLGPU_BACKEND False)
116+
set(ENABLE_MKLCPU_BACKEND False)
117+
endif()
118+
FetchContent_Declare(
119+
onemkl_interfaces_library
120+
GIT_REPOSITORY https://github.com/oneapi-src/oneMKL.git
121+
GIT_TAG f2d2dcb4213a435bb60fbb88320c5f24892423ce
122+
)
123+
FetchContent_MakeAvailable(onemkl_interfaces_library)
124+
endif()
125+
70126
if(WIN32)
71127
string(CONCAT WARNING_FLAGS
72128
"-Wall "

dpnp/backend/extensions/fft/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ set(_module_src
3434
pybind11_add_module(${python_module_name} MODULE ${_module_src})
3535
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
3636

37+
if(_dpnp_sycl_targets)
38+
# make fat binary
39+
target_compile_options(
40+
${python_module_name}
41+
PRIVATE
42+
-fsycl-targets=${_dpnp_sycl_targets}
43+
)
44+
target_link_options(
45+
${python_module_name}
46+
PRIVATE
47+
-fsycl-targets=${_dpnp_sycl_targets}
48+
)
49+
endif()
50+
3751
if (WIN32)
3852
if (${CMAKE_VERSION} VERSION_LESS "3.27")
3953
# this is a work-around for target_link_options inserting option after -link option, cause
@@ -68,7 +82,12 @@ if (DPNP_GENERATE_COVERAGE)
6882
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
6983
endif()
7084

71-
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::DFT)
85+
if(_use_onemkl_interfaces)
86+
target_link_libraries(${python_module_name} PUBLIC onemkl)
87+
target_compile_options(${python_module_name} PRIVATE -DUSE_ONEMKL_INTERFACES)
88+
else()
89+
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::DFT)
90+
endif()
7291

7392
install(TARGETS ${python_module_name}
7493
DESTINATION "dpnp/backend/extensions/fft"

dpnp/backend/extensions/fft/common.hpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,26 +187,32 @@ class DescriptorWrapper
187187
// config_param::PLACEMENT
188188
bool get_in_place()
189189
{
190-
// TODO: replace when MKLD-10506 is implemented
191-
// mkl_dft::config_value placement;
190+
#if defined(USE_ONEMKL_INTERFACES)
191+
mkl_dft::config_value placement;
192+
descr_.get_value(mkl_dft::config_param::PLACEMENT, &placement);
193+
return (placement == mkl_dft::config_value::INPLACE);
194+
#else
195+
// TODO: remove branch when MKLD-10506 is implemented
192196
DFTI_CONFIG_VALUE placement;
193-
194197
descr_.get_value(mkl_dft::config_param::PLACEMENT, &placement);
195-
// TODO: replace when MKLD-10506 is implemented
196-
// return (placement == mkl_dft::config_value::INPLACE);
197198
return (placement == DFTI_CONFIG_VALUE::DFTI_INPLACE);
199+
#endif // USE_ONEMKL_INTERFACES
198200
}
199201

200202
void set_in_place(const bool &in_place_request)
201203
{
202-
// TODO: replace when MKLD-10506 is implemented
203-
// descr_.set_value(mkl_dft::config_param::PLACEMENT, (in_place_request)
204-
// ? mkl_dft::config_value::INPLACE :
205-
// mkl_dft::config_value::NOT_INPLACE);
204+
#if defined(USE_ONEMKL_INTERFACES)
205+
descr_.set_value(mkl_dft::config_param::PLACEMENT,
206+
(in_place_request)
207+
? mkl_dft::config_value::INPLACE
208+
: mkl_dft::config_value::NOT_INPLACE);
209+
#else
210+
// TODO: remove branch when MKLD-10506 is implemented
206211
descr_.set_value(mkl_dft::config_param::PLACEMENT,
207212
(in_place_request)
208213
? DFTI_CONFIG_VALUE::DFTI_INPLACE
209214
: DFTI_CONFIG_VALUE::DFTI_NOT_INPLACE);
215+
#endif // USE_ONEMKL_INTERFACES
210216
}
211217

212218
// config_param::PRECISION
@@ -221,14 +227,16 @@ class DescriptorWrapper
221227
// config_param::COMMIT_STATUS
222228
bool is_committed()
223229
{
224-
// TODO: replace when MKLD-10506 is implemented
225-
// mkl_dft::config_value committed;
230+
#if defined(USE_ONEMKL_INTERFACES)
231+
mkl_dft::config_value committed;
232+
descr_.get_value(mkl_dft::config_param::COMMIT_STATUS, &committed);
233+
return (committed == mkl_dft::config_value::COMMITTED);
234+
#else
235+
// TODO: remove branch when MKLD-10506 is implemented
226236
DFTI_CONFIG_VALUE committed;
227-
228237
descr_.get_value(mkl_dft::config_param::COMMIT_STATUS, &committed);
229-
// TODO: replace when MKLD-10506 is implemented
230-
// return (committed == mkl_dft::config_value::COMMITTED);
231238
return (committed == DFTI_CONFIG_VALUE::DFTI_COMMITTED);
239+
#endif // USE_ONEMKL_INTERFACES
232240
}
233241

234242
private:

dpnp/backend/extensions/fft/out_of_place.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// THE POSSIBILITY OF SUCH DAMAGE.
2424
//*****************************************************************************
2525

26-
#include <oneapi/mkl/dfti.hpp>
26+
#include <oneapi/mkl.hpp>
2727
#include <sycl/sycl.hpp>
2828

2929
#include <dpctl4pybind11.hpp>

dpnp/backend/extensions/lapack/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ set(_module_src
5151
pybind11_add_module(${python_module_name} MODULE ${_module_src})
5252
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
5353

54+
if(_dpnp_sycl_targets)
55+
# make fat binary
56+
target_compile_options(
57+
${python_module_name}
58+
PRIVATE
59+
-fsycl-targets=${_dpnp_sycl_targets}
60+
)
61+
target_link_options(
62+
${python_module_name}
63+
PRIVATE
64+
-fsycl-targets=${_dpnp_sycl_targets}
65+
)
66+
endif()
67+
5468
if (WIN32)
5569
if (${CMAKE_VERSION} VERSION_LESS "3.27")
5670
# this is a work-around for target_link_options inserting option after -link option, cause
@@ -85,7 +99,12 @@ if (DPNP_GENERATE_COVERAGE)
8599
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
86100
endif()
87101

88-
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::LAPACK)
102+
if(_use_onemkl_interfaces)
103+
target_link_libraries(${python_module_name} PUBLIC onemkl)
104+
target_compile_options(${python_module_name} PRIVATE -DUSE_ONEMKL_INTERFACES)
105+
else()
106+
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::LAPACK)
107+
endif()
89108

90109
install(TARGETS ${python_module_name}
91110
DESTINATION "dpnp/backend/extensions/lapack"

dpnp/backend/extensions/lapack/gesv.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ static sycl::event gesv_impl(sycl::queue &exec_q,
5656
char *in_b,
5757
const std::vector<sycl::event> &depends)
5858
{
59+
#if defined(USE_ONEMKL_INTERFACES)
60+
// Temporary flag for build only
61+
// FIXME: Need to implement by using lapack::getrf and lapack::getrs
62+
std::logic_error("Not Implemented");
63+
#else
5964
type_utils::validate_type_for_device<T>(exec_q);
6065

6166
T *a = reinterpret_cast<T *>(in_a);
@@ -129,6 +134,7 @@ static sycl::event gesv_impl(sycl::queue &exec_q,
129134
});
130135

131136
return ht_ev;
137+
#endif // USE_ONEMKL_INTERFACES
132138
}
133139

134140
std::pair<sycl::event, sycl::event>

dpnp/backend/extensions/vm/CMakeLists.txt

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,49 @@
2323
# THE POSSIBILITY OF SUCH DAMAGE.
2424
# *****************************************************************************
2525

26-
set(_elementwise_sources
27-
${CMAKE_CURRENT_SOURCE_DIR}/abs.cpp
28-
${CMAKE_CURRENT_SOURCE_DIR}/acos.cpp
29-
${CMAKE_CURRENT_SOURCE_DIR}/acosh.cpp
30-
${CMAKE_CURRENT_SOURCE_DIR}/add.cpp
31-
${CMAKE_CURRENT_SOURCE_DIR}/asin.cpp
32-
${CMAKE_CURRENT_SOURCE_DIR}/asinh.cpp
33-
${CMAKE_CURRENT_SOURCE_DIR}/atan.cpp
34-
${CMAKE_CURRENT_SOURCE_DIR}/atan2.cpp
35-
${CMAKE_CURRENT_SOURCE_DIR}/atanh.cpp
36-
${CMAKE_CURRENT_SOURCE_DIR}/cbrt.cpp
37-
${CMAKE_CURRENT_SOURCE_DIR}/ceil.cpp
38-
${CMAKE_CURRENT_SOURCE_DIR}/conj.cpp
39-
${CMAKE_CURRENT_SOURCE_DIR}/cos.cpp
40-
${CMAKE_CURRENT_SOURCE_DIR}/cosh.cpp
41-
${CMAKE_CURRENT_SOURCE_DIR}/div.cpp
42-
${CMAKE_CURRENT_SOURCE_DIR}/exp.cpp
43-
${CMAKE_CURRENT_SOURCE_DIR}/exp2.cpp
44-
${CMAKE_CURRENT_SOURCE_DIR}/expm1.cpp
45-
${CMAKE_CURRENT_SOURCE_DIR}/floor.cpp
46-
${CMAKE_CURRENT_SOURCE_DIR}/fmax.cpp
47-
${CMAKE_CURRENT_SOURCE_DIR}/fmin.cpp
48-
${CMAKE_CURRENT_SOURCE_DIR}/fmod.cpp
49-
${CMAKE_CURRENT_SOURCE_DIR}/hypot.cpp
50-
${CMAKE_CURRENT_SOURCE_DIR}/ln.cpp
51-
${CMAKE_CURRENT_SOURCE_DIR}/log10.cpp
52-
${CMAKE_CURRENT_SOURCE_DIR}/log1p.cpp
53-
${CMAKE_CURRENT_SOURCE_DIR}/log2.cpp
54-
${CMAKE_CURRENT_SOURCE_DIR}/mul.cpp
55-
${CMAKE_CURRENT_SOURCE_DIR}/nextafter.cpp
56-
${CMAKE_CURRENT_SOURCE_DIR}/pow.cpp
57-
${CMAKE_CURRENT_SOURCE_DIR}/rint.cpp
58-
${CMAKE_CURRENT_SOURCE_DIR}/sin.cpp
59-
${CMAKE_CURRENT_SOURCE_DIR}/sinh.cpp
60-
${CMAKE_CURRENT_SOURCE_DIR}/sqr.cpp
61-
${CMAKE_CURRENT_SOURCE_DIR}/sqrt.cpp
62-
${CMAKE_CURRENT_SOURCE_DIR}/sub.cpp
63-
${CMAKE_CURRENT_SOURCE_DIR}/tan.cpp
64-
${CMAKE_CURRENT_SOURCE_DIR}/tanh.cpp
65-
${CMAKE_CURRENT_SOURCE_DIR}/trunc.cpp
26+
if(NOT _use_onemkl_interfaces)
27+
set(_elementwise_sources
28+
${CMAKE_CURRENT_SOURCE_DIR}/abs.cpp
29+
${CMAKE_CURRENT_SOURCE_DIR}/acos.cpp
30+
${CMAKE_CURRENT_SOURCE_DIR}/acosh.cpp
31+
${CMAKE_CURRENT_SOURCE_DIR}/add.cpp
32+
${CMAKE_CURRENT_SOURCE_DIR}/asin.cpp
33+
${CMAKE_CURRENT_SOURCE_DIR}/asinh.cpp
34+
${CMAKE_CURRENT_SOURCE_DIR}/atan.cpp
35+
${CMAKE_CURRENT_SOURCE_DIR}/atan2.cpp
36+
${CMAKE_CURRENT_SOURCE_DIR}/atanh.cpp
37+
${CMAKE_CURRENT_SOURCE_DIR}/cbrt.cpp
38+
${CMAKE_CURRENT_SOURCE_DIR}/ceil.cpp
39+
${CMAKE_CURRENT_SOURCE_DIR}/conj.cpp
40+
${CMAKE_CURRENT_SOURCE_DIR}/cos.cpp
41+
${CMAKE_CURRENT_SOURCE_DIR}/cosh.cpp
42+
${CMAKE_CURRENT_SOURCE_DIR}/div.cpp
43+
${CMAKE_CURRENT_SOURCE_DIR}/exp.cpp
44+
${CMAKE_CURRENT_SOURCE_DIR}/exp2.cpp
45+
${CMAKE_CURRENT_SOURCE_DIR}/expm1.cpp
46+
${CMAKE_CURRENT_SOURCE_DIR}/floor.cpp
47+
${CMAKE_CURRENT_SOURCE_DIR}/fmax.cpp
48+
${CMAKE_CURRENT_SOURCE_DIR}/fmin.cpp
49+
${CMAKE_CURRENT_SOURCE_DIR}/fmod.cpp
50+
${CMAKE_CURRENT_SOURCE_DIR}/hypot.cpp
51+
${CMAKE_CURRENT_SOURCE_DIR}/ln.cpp
52+
${CMAKE_CURRENT_SOURCE_DIR}/log10.cpp
53+
${CMAKE_CURRENT_SOURCE_DIR}/log1p.cpp
54+
${CMAKE_CURRENT_SOURCE_DIR}/log2.cpp
55+
${CMAKE_CURRENT_SOURCE_DIR}/mul.cpp
56+
${CMAKE_CURRENT_SOURCE_DIR}/nextafter.cpp
57+
${CMAKE_CURRENT_SOURCE_DIR}/pow.cpp
58+
${CMAKE_CURRENT_SOURCE_DIR}/rint.cpp
59+
${CMAKE_CURRENT_SOURCE_DIR}/sin.cpp
60+
${CMAKE_CURRENT_SOURCE_DIR}/sinh.cpp
61+
${CMAKE_CURRENT_SOURCE_DIR}/sqr.cpp
62+
${CMAKE_CURRENT_SOURCE_DIR}/sqrt.cpp
63+
${CMAKE_CURRENT_SOURCE_DIR}/sub.cpp
64+
${CMAKE_CURRENT_SOURCE_DIR}/tan.cpp
65+
${CMAKE_CURRENT_SOURCE_DIR}/tanh.cpp
66+
${CMAKE_CURRENT_SOURCE_DIR}/trunc.cpp
6667
)
68+
endif()
6769

6870
set(_module_src
6971
# TODO: remove sources from `elementwise_functions` folder
@@ -112,7 +114,11 @@ if (DPNP_GENERATE_COVERAGE)
112114
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
113115
endif()
114116

115-
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::VM)
117+
if(_use_onemkl_interfaces)
118+
target_compile_options(${python_module_name} PRIVATE -DUSE_ONEMKL_INTERFACES)
119+
else()
120+
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::VM)
121+
endif()
116122

117123
install(TARGETS ${python_module_name}
118124
DESTINATION "dpnp/backend/extensions/vm"

dpnp/backend/extensions/vm/vm_py.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
// THE POSSIBILITY OF SUCH DAMAGE.
2424
//*****************************************************************************
2525
//
26-
// This file defines functions of dpnp.backend._lapack_impl extensions
26+
// This file defines functions of dpnp.backend._vm_impl extensions
2727
//
2828
//*****************************************************************************
2929

30+
#if not defined(USE_ONEMKL_INTERFACES)
3031
#include "abs.hpp"
3132
#include "acos.hpp"
3233
#include "acosh.hpp"
@@ -68,9 +69,13 @@
6869
#include "trunc.hpp"
6970

7071
namespace vm_ns = dpnp::extensions::vm;
72+
#endif // USE_ONEMKL_INTERFACES
73+
74+
#include <pybind11/pybind11.h>
7175

7276
PYBIND11_MODULE(_vm_impl, m)
7377
{
78+
#if not defined(USE_ONEMKL_INTERFACES)
7479
vm_ns::init_abs(m);
7580
vm_ns::init_acos(m);
7681
vm_ns::init_acosh(m);
@@ -110,4 +115,15 @@ PYBIND11_MODULE(_vm_impl, m)
110115
vm_ns::init_tan(m);
111116
vm_ns::init_tanh(m);
112117
vm_ns::init_trunc(m);
118+
#endif // USE_ONEMKL_INTERFACES
119+
m.def(
120+
"_is_available",
121+
[](void) {
122+
#if defined(USE_ONEMKL_INTERFACES)
123+
return false;
124+
#else
125+
return true;
126+
#endif // USE_ONEMKL_INTERFACES
127+
},
128+
"Check if the OneMKL VM library can be used.");
113129
}

0 commit comments

Comments
 (0)