Skip to content

Commit 901463c

Browse files
authored
Merge 3fccd62 into 08928bf
2 parents 08928bf + 3fccd62 commit 901463c

File tree

11 files changed

+266
-146
lines changed

11 files changed

+266
-146
lines changed

CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,51 @@ 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+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
75+
set(_dpnp_sycl_targets)
76+
set(_dpnp_use_onemkl OFF)
77+
if ("x${DPNP_SYCL_TARGETS}" STREQUAL "x")
78+
if(DPNP_TARGET_CUDA)
79+
set(_dpnp_use_onemkl ON)
80+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPNP_TARGET_CUDA=1")
81+
set(_dpnp_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
82+
else()
83+
if(DEFINED ENV{DPNP_TARGET_CUDA})
84+
set(_dpnp_use_onemkl ON)
85+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPNP_TARGET_CUDA=1")
86+
set(_dpnp_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
87+
endif()
88+
endif()
89+
else()
90+
set(_dpnp_sycl_targets ${DPNP_SYCL_TARGETS})
91+
endif()
92+
93+
if(_dpnp_sycl_targets)
94+
message(STATUS "Compiling for -fsycl-targets=${_dpnp_sycl_targets}")
95+
endif()
96+
97+
if(_dpnp_use_onemkl)
98+
set(BUILD_FUNCTIONAL_TESTS False)
99+
set(BUILD_EXAMPLES False)
100+
set(ENABLE_CUBLAS_BACKEND False)
101+
set(ENABLE_CUSOLVER_BACKEND True)
102+
set(ENABLE_CUFFT_BACKEND True)
103+
set(ENABLE_CURAND_BACKEND False)
104+
set(ENABLE_MKLGPU_BACKEND False)
105+
set(ENABLE_MKLCPU_BACKEND False)
106+
FetchContent_Declare(
107+
onemkl_interface_library
108+
GIT_REPOSITORY https://github.com/oneapi-src/oneMKL.git
109+
GIT_TAG develop
110+
)
111+
FetchContent_MakeAvailable(onemkl_interface_library)
112+
endif()
113+
114+
70115
if(WIN32)
71116
string(CONCAT WARNING_FLAGS
72117
"-Wall "

dpnp/backend/extensions/fft/CMakeLists.txt

Lines changed: 19 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,11 @@ 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(_dpnp_use_onemkl)
86+
target_link_libraries(${python_module_name} PUBLIC onemkl)
87+
else()
88+
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::DFT)
89+
endif()
7290

7391
install(TARGETS ${python_module_name}
7492
DESTINATION "dpnp/backend/extensions/fft"

dpnp/backend/extensions/fft/common.hpp

Lines changed: 19 additions & 11 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+
#if DPNP_TARGET_CUDA
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
190195
// TODO: replace when MKLD-10506 is implemented
191-
// mkl_dft::config_value placement;
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
198200
}
199201

200202
void set_in_place(const bool &in_place_request)
201203
{
204+
#if DPNP_TARGET_CUDA
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
202210
// 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);
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
210216
}
211217

212218
// config_param::PRECISION
@@ -221,14 +227,16 @@ class DescriptorWrapper
221227
// config_param::COMMIT_STATUS
222228
bool is_committed()
223229
{
230+
#if DPNP_TARGET_CUDA
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
224235
// TODO: replace when MKLD-10506 is implemented
225-
// mkl_dft::config_value committed;
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
232240
}
233241

234242
private:

dpnp/backend/extensions/fft/out_of_place.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
// THE POSSIBILITY OF SUCH DAMAGE.
2424
//*****************************************************************************
2525

26+
#if !DPNP_TARGET_CUDA
2627
#include <oneapi/mkl/dfti.hpp>
28+
#endif
29+
2730
#include <sycl/sycl.hpp>
2831

2932
#include <dpctl4pybind11.hpp>

dpnp/backend/extensions/lapack/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ set(_module_src
4848
pybind11_add_module(${python_module_name} MODULE ${_module_src})
4949
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
5050

51+
if(_dpnp_sycl_targets)
52+
# make fat binary
53+
target_compile_options(
54+
${python_module_name}
55+
PRIVATE
56+
-fsycl-targets=${_dpnp_sycl_targets}
57+
)
58+
target_link_options(
59+
${python_module_name}
60+
PRIVATE
61+
-fsycl-targets=${_dpnp_sycl_targets}
62+
)
63+
endif()
64+
5165
if (WIN32)
5266
if (${CMAKE_VERSION} VERSION_LESS "3.27")
5367
# this is a work-around for target_link_options inserting option after -link option, cause
@@ -82,7 +96,11 @@ if (DPNP_GENERATE_COVERAGE)
8296
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
8397
endif()
8498

85-
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::LAPACK)
99+
if(_dpnp_use_onemkl)
100+
target_link_libraries(${python_module_name} PUBLIC onemkl)
101+
else()
102+
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::LAPACK)
103+
endif()
86104

87105
install(TARGETS ${python_module_name}
88106
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
@@ -65,6 +65,11 @@ static sycl::event gesv_impl(sycl::queue exec_q,
6565
std::vector<sycl::event> &host_task_events,
6666
const std::vector<sycl::event> &depends)
6767
{
68+
#if DPNP_TARGET_CUDA
69+
// Temporary flag for build only
70+
// FIXME: Need to implement by using lapack::getrf and lapack::getrs
71+
std::logic_error("Not Implemented");
72+
#else
6873
type_utils::validate_type_for_device<T>(exec_q);
6974

7075
T *a = reinterpret_cast<T *>(in_a);
@@ -167,6 +172,7 @@ static sycl::event gesv_impl(sycl::queue exec_q,
167172
host_task_events.push_back(clean_up_event);
168173

169174
return gesv_event;
175+
#endif
170176
}
171177

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

dpnp/backend/extensions/vm/CMakeLists.txt

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,48 @@
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}/pow.cpp
56-
${CMAKE_CURRENT_SOURCE_DIR}/rint.cpp
57-
${CMAKE_CURRENT_SOURCE_DIR}/sin.cpp
58-
${CMAKE_CURRENT_SOURCE_DIR}/sinh.cpp
59-
${CMAKE_CURRENT_SOURCE_DIR}/sqr.cpp
60-
${CMAKE_CURRENT_SOURCE_DIR}/sqrt.cpp
61-
${CMAKE_CURRENT_SOURCE_DIR}/sub.cpp
62-
${CMAKE_CURRENT_SOURCE_DIR}/tan.cpp
63-
${CMAKE_CURRENT_SOURCE_DIR}/tanh.cpp
64-
${CMAKE_CURRENT_SOURCE_DIR}/trunc.cpp
26+
if(NOT _dpnp_use_onemkl)
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}/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
6566
)
67+
endif()
6668

6769
set(_module_src
6870
# TODO: remove sources from `elementwise_functions` folder
@@ -111,7 +113,9 @@ if (DPNP_GENERATE_COVERAGE)
111113
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
112114
endif()
113115

114-
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::VM)
116+
if(NOT _dpnp_use_onemkl)
117+
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::VM)
118+
endif()
115119

116120
install(TARGETS ${python_module_name}
117121
DESTINATION "dpnp/backend/extensions/vm"

dpnp/backend/extensions/vm/vm_py.cpp

Lines changed: 18 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 !DPNP_TARGET_CUDA
3031
#include "abs.hpp"
3132
#include "acos.hpp"
3233
#include "acosh.hpp"
@@ -67,9 +68,22 @@
6768
#include "trunc.hpp"
6869

6970
namespace vm_ns = dpnp::extensions::vm;
71+
#endif
72+
73+
#include <pybind11/pybind11.h>
74+
75+
bool mkl_vm_is_defined()
76+
{
77+
#if DPNP_TARGET_CUDA
78+
return false;
79+
#else
80+
return true;
81+
#endif
82+
}
7083

7184
PYBIND11_MODULE(_vm_impl, m)
7285
{
86+
#if !DPNP_TARGET_CUDA
7387
vm_ns::init_abs(m);
7488
vm_ns::init_acos(m);
7589
vm_ns::init_acosh(m);
@@ -108,4 +122,7 @@ PYBIND11_MODULE(_vm_impl, m)
108122
vm_ns::init_tan(m);
109123
vm_ns::init_tanh(m);
110124
vm_ns::init_trunc(m);
125+
#endif
126+
m.def("mkl_vm_is_defined", mkl_vm_is_defined,
127+
"Check if the OneMKL VM library can be used.");
111128
}

dpnp/dpnp_algo/dpnp_elementwise_common.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
)
3333

3434
import dpnp
35+
import dpnp.backend.extensions.vm._vm_impl as vmi
3536
from dpnp.dpnp_array import dpnp_array
3637

3738
__all__ = [
@@ -111,11 +112,12 @@ def _call_func(src, dst, sycl_queue, depends=None):
111112
if depends is None:
112113
depends = []
113114

114-
if mkl_fn_to_call is not None and mkl_fn_to_call(
115-
sycl_queue, src, dst
116-
):
117-
# call pybind11 extension for unary function from OneMKL VM
118-
return mkl_impl_fn(sycl_queue, src, dst, depends)
115+
if vmi.mkl_vm_is_defined() and mkl_fn_to_call is not None:
116+
if getattr(vmi, mkl_fn_to_call)(sycl_queue, src, dst):
117+
# call pybind11 extension for unary function from OneMKL VM
118+
return getattr(vmi, mkl_impl_fn)(
119+
sycl_queue, src, dst, depends
120+
)
119121
return unary_dp_impl_fn(src, dst, sycl_queue, depends)
120122

121123
super().__init__(
@@ -263,11 +265,12 @@ def _call_func(src1, src2, dst, sycl_queue, depends=None):
263265
if depends is None:
264266
depends = []
265267

266-
if mkl_fn_to_call is not None and mkl_fn_to_call(
267-
sycl_queue, src1, src2, dst
268-
):
269-
# call pybind11 extension for binary function from OneMKL VM
270-
return mkl_impl_fn(sycl_queue, src1, src2, dst, depends)
268+
if vmi.mkl_vm_is_defined() and mkl_fn_to_call is not None:
269+
if getattr(vmi, mkl_fn_to_call)(sycl_queue, src1, src2, dst):
270+
# call pybind11 extension for binary function from OneMKL VM
271+
return getattr(vmi, mkl_impl_fn)(
272+
sycl_queue, src1, src2, dst, depends
273+
)
271274
return binary_dp_impl_fn(src1, src2, dst, sycl_queue, depends)
272275

273276
super().__init__(

0 commit comments

Comments
 (0)