Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,51 @@ find_package(Dpctl REQUIRED)
message(STATUS "Dpctl_INCLUDE_DIR=" ${Dpctl_INCLUDE_DIR})
message(STATUS "Dpctl_TENSOR_INCLUDE_DIR=" ${Dpctl_TENSOR_INCLUDE_DIR})

option(DPNP_TARGET_CUDA
"Build DPNP to target CUDA devices"
OFF
)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
Comment thread
npolina4 marked this conversation as resolved.
Outdated
set(_dpnp_sycl_targets)
set(_dpnp_use_onemkl OFF)
Comment thread
npolina4 marked this conversation as resolved.
Outdated
if ("x${DPNP_SYCL_TARGETS}" STREQUAL "x")
if(DPNP_TARGET_CUDA)
set(_dpnp_use_onemkl ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPNP_TARGET_CUDA=1")
Comment thread
npolina4 marked this conversation as resolved.
Outdated
set(_dpnp_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
else()
if(DEFINED ENV{DPNP_TARGET_CUDA})
set(_dpnp_use_onemkl ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPNP_TARGET_CUDA=1")
set(_dpnp_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
endif()
endif()
else()
set(_dpnp_sycl_targets ${DPNP_SYCL_TARGETS})
endif()

if(_dpnp_sycl_targets)
message(STATUS "Compiling for -fsycl-targets=${_dpnp_sycl_targets}")
endif()

if(_dpnp_use_onemkl)
set(BUILD_FUNCTIONAL_TESTS False)
set(BUILD_EXAMPLES False)
set(ENABLE_CUBLAS_BACKEND False)
set(ENABLE_CUSOLVER_BACKEND True)
set(ENABLE_CUFFT_BACKEND True)
set(ENABLE_CURAND_BACKEND False)
set(ENABLE_MKLGPU_BACKEND False)
set(ENABLE_MKLCPU_BACKEND False)
FetchContent_Declare(
onemkl_interface_library
GIT_REPOSITORY https://github.com/oneapi-src/oneMKL.git
GIT_TAG develop
Comment thread
npolina4 marked this conversation as resolved.
Outdated
)
FetchContent_MakeAvailable(onemkl_interface_library)
endif()


if(WIN32)
string(CONCAT WARNING_FLAGS
"-Wall "
Expand Down
20 changes: 19 additions & 1 deletion dpnp/backend/extensions/fft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ set(_module_src
pybind11_add_module(${python_module_name} MODULE ${_module_src})
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})

if(_dpnp_sycl_targets)
# make fat binary
target_compile_options(
${python_module_name}
PRIVATE
-fsycl-targets=${_dpnp_sycl_targets}
)
target_link_options(
${python_module_name}
PRIVATE
-fsycl-targets=${_dpnp_sycl_targets}
)
endif()

if (WIN32)
if (${CMAKE_VERSION} VERSION_LESS "3.27")
# this is a work-around for target_link_options inserting option after -link option, cause
Expand Down Expand Up @@ -68,7 +82,11 @@ if (DPNP_GENERATE_COVERAGE)
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
endif()

target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::DFT)
if(_dpnp_use_onemkl)
target_link_libraries(${python_module_name} PUBLIC onemkl)
else()
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::DFT)
endif()

install(TARGETS ${python_module_name}
DESTINATION "dpnp/backend/extensions/fft"
Expand Down
30 changes: 19 additions & 11 deletions dpnp/backend/extensions/fft/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,32 @@ class DescriptorWrapper
// config_param::PLACEMENT
bool get_in_place()
{
#if DPNP_TARGET_CUDA
Comment thread
npolina4 marked this conversation as resolved.
Outdated
mkl_dft::config_value placement;
descr_.get_value(mkl_dft::config_param::PLACEMENT, &placement);
return (placement == mkl_dft::config_value::INPLACE);
#else
// TODO: replace when MKLD-10506 is implemented
// mkl_dft::config_value placement;
Comment thread
npolina4 marked this conversation as resolved.
DFTI_CONFIG_VALUE placement;

descr_.get_value(mkl_dft::config_param::PLACEMENT, &placement);
// TODO: replace when MKLD-10506 is implemented
// return (placement == mkl_dft::config_value::INPLACE);
return (placement == DFTI_CONFIG_VALUE::DFTI_INPLACE);
#endif
Comment thread
npolina4 marked this conversation as resolved.
Outdated
}

void set_in_place(const bool &in_place_request)
{
#if DPNP_TARGET_CUDA
descr_.set_value(mkl_dft::config_param::PLACEMENT,
(in_place_request)
? mkl_dft::config_value::INPLACE
: mkl_dft::config_value::NOT_INPLACE);
#else
// TODO: replace when MKLD-10506 is implemented
// descr_.set_value(mkl_dft::config_param::PLACEMENT, (in_place_request)
// ? mkl_dft::config_value::INPLACE :
// mkl_dft::config_value::NOT_INPLACE);
descr_.set_value(mkl_dft::config_param::PLACEMENT,
(in_place_request)
? DFTI_CONFIG_VALUE::DFTI_INPLACE
: DFTI_CONFIG_VALUE::DFTI_NOT_INPLACE);
#endif
}

// config_param::PRECISION
Expand All @@ -221,14 +227,16 @@ class DescriptorWrapper
// config_param::COMMIT_STATUS
bool is_committed()
{
#if DPNP_TARGET_CUDA
mkl_dft::config_value committed;
descr_.get_value(mkl_dft::config_param::COMMIT_STATUS, &committed);
return (committed == mkl_dft::config_value::COMMITTED);
#else
// TODO: replace when MKLD-10506 is implemented
// mkl_dft::config_value committed;
DFTI_CONFIG_VALUE committed;

descr_.get_value(mkl_dft::config_param::COMMIT_STATUS, &committed);
// TODO: replace when MKLD-10506 is implemented
// return (committed == mkl_dft::config_value::COMMITTED);
return (committed == DFTI_CONFIG_VALUE::DFTI_COMMITTED);
#endif
}

private:
Expand Down
3 changes: 3 additions & 0 deletions dpnp/backend/extensions/fft/out_of_place.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
// THE POSSIBILITY OF SUCH DAMAGE.
//*****************************************************************************

#if !DPNP_TARGET_CUDA
Comment thread
npolina4 marked this conversation as resolved.
Outdated
#include <oneapi/mkl/dfti.hpp>
Comment thread
npolina4 marked this conversation as resolved.
Outdated
#endif

#include <sycl/sycl.hpp>

#include <dpctl4pybind11.hpp>
Expand Down
20 changes: 19 additions & 1 deletion dpnp/backend/extensions/lapack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ set(_module_src
pybind11_add_module(${python_module_name} MODULE ${_module_src})
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})

if(_dpnp_sycl_targets)
# make fat binary
target_compile_options(
${python_module_name}
PRIVATE
-fsycl-targets=${_dpnp_sycl_targets}
)
target_link_options(
${python_module_name}
PRIVATE
-fsycl-targets=${_dpnp_sycl_targets}
)
endif()

if (WIN32)
if (${CMAKE_VERSION} VERSION_LESS "3.27")
# this is a work-around for target_link_options inserting option after -link option, cause
Expand Down Expand Up @@ -82,7 +96,11 @@ if (DPNP_GENERATE_COVERAGE)
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
endif()

target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::LAPACK)
if(_dpnp_use_onemkl)
target_link_libraries(${python_module_name} PUBLIC onemkl)
else()
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::LAPACK)
endif()

install(TARGETS ${python_module_name}
DESTINATION "dpnp/backend/extensions/lapack"
Expand Down
6 changes: 6 additions & 0 deletions dpnp/backend/extensions/lapack/gesv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ static sycl::event gesv_impl(sycl::queue exec_q,
std::vector<sycl::event> &host_task_events,
const std::vector<sycl::event> &depends)
{
#if DPNP_TARGET_CUDA
// Temporary flag for build only
// FIXME: Need to implement by using lapack::getrf and lapack::getrs
std::logic_error("Not Implemented");
Comment thread
antonwolfy marked this conversation as resolved.
#else
type_utils::validate_type_for_device<T>(exec_q);

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

return gesv_event;
#endif
}

std::pair<sycl::event, sycl::event>
Expand Down
84 changes: 44 additions & 40 deletions dpnp/backend/extensions/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,48 @@
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

set(_elementwise_sources
${CMAKE_CURRENT_SOURCE_DIR}/abs.cpp
${CMAKE_CURRENT_SOURCE_DIR}/acos.cpp
${CMAKE_CURRENT_SOURCE_DIR}/acosh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/add.cpp
${CMAKE_CURRENT_SOURCE_DIR}/asin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/asinh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/atan.cpp
${CMAKE_CURRENT_SOURCE_DIR}/atan2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/atanh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cbrt.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ceil.cpp
${CMAKE_CURRENT_SOURCE_DIR}/conj.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cos.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cosh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/div.cpp
${CMAKE_CURRENT_SOURCE_DIR}/exp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/exp2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/expm1.cpp
${CMAKE_CURRENT_SOURCE_DIR}/floor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fmax.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fmin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fmod.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hypot.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ln.cpp
${CMAKE_CURRENT_SOURCE_DIR}/log10.cpp
${CMAKE_CURRENT_SOURCE_DIR}/log1p.cpp
${CMAKE_CURRENT_SOURCE_DIR}/log2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mul.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rint.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sinh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sqr.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sqrt.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sub.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tan.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tanh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/trunc.cpp
if(NOT _dpnp_use_onemkl)
set(_elementwise_sources
${CMAKE_CURRENT_SOURCE_DIR}/abs.cpp
${CMAKE_CURRENT_SOURCE_DIR}/acos.cpp
${CMAKE_CURRENT_SOURCE_DIR}/acosh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/add.cpp
${CMAKE_CURRENT_SOURCE_DIR}/asin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/asinh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/atan.cpp
${CMAKE_CURRENT_SOURCE_DIR}/atan2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/atanh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cbrt.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ceil.cpp
${CMAKE_CURRENT_SOURCE_DIR}/conj.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cos.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cosh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/div.cpp
${CMAKE_CURRENT_SOURCE_DIR}/exp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/exp2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/expm1.cpp
${CMAKE_CURRENT_SOURCE_DIR}/floor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fmax.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fmin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fmod.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hypot.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ln.cpp
${CMAKE_CURRENT_SOURCE_DIR}/log10.cpp
${CMAKE_CURRENT_SOURCE_DIR}/log1p.cpp
${CMAKE_CURRENT_SOURCE_DIR}/log2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mul.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rint.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sinh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sqr.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sqrt.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sub.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tan.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tanh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/trunc.cpp
)
endif()

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

target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::VM)
if(NOT _dpnp_use_onemkl)
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::VM)
endif()

install(TARGETS ${python_module_name}
DESTINATION "dpnp/backend/extensions/vm"
Expand Down
19 changes: 18 additions & 1 deletion dpnp/backend/extensions/vm/vm_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
// THE POSSIBILITY OF SUCH DAMAGE.
//*****************************************************************************
//
// This file defines functions of dpnp.backend._lapack_impl extensions
// This file defines functions of dpnp.backend._vm_impl extensions
//
//*****************************************************************************

#if !DPNP_TARGET_CUDA
#include "abs.hpp"
#include "acos.hpp"
#include "acosh.hpp"
Expand Down Expand Up @@ -67,9 +68,22 @@
#include "trunc.hpp"

namespace vm_ns = dpnp::extensions::vm;
#endif

#include <pybind11/pybind11.h>

bool mkl_vm_is_defined()
{
#if DPNP_TARGET_CUDA
return false;
#else
return true;
#endif
}

PYBIND11_MODULE(_vm_impl, m)
{
#if !DPNP_TARGET_CUDA
vm_ns::init_abs(m);
vm_ns::init_acos(m);
vm_ns::init_acosh(m);
Expand Down Expand Up @@ -108,4 +122,7 @@ PYBIND11_MODULE(_vm_impl, m)
vm_ns::init_tan(m);
vm_ns::init_tanh(m);
vm_ns::init_trunc(m);
#endif
m.def("mkl_vm_is_defined", mkl_vm_is_defined,
"Check if the OneMKL VM library can be used.");
Comment thread
npolina4 marked this conversation as resolved.
Outdated
}
23 changes: 13 additions & 10 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
)

import dpnp
import dpnp.backend.extensions.vm._vm_impl as vmi
from dpnp.dpnp_array import dpnp_array

__all__ = [
Expand Down Expand Up @@ -111,11 +112,12 @@ def _call_func(src, dst, sycl_queue, depends=None):
if depends is None:
depends = []

if mkl_fn_to_call is not None and mkl_fn_to_call(
sycl_queue, src, dst
):
# call pybind11 extension for unary function from OneMKL VM
return mkl_impl_fn(sycl_queue, src, dst, depends)
if vmi.mkl_vm_is_defined() and mkl_fn_to_call is not None:
if getattr(vmi, mkl_fn_to_call)(sycl_queue, src, dst):
# call pybind11 extension for unary function from OneMKL VM
return getattr(vmi, mkl_impl_fn)(
sycl_queue, src, dst, depends
)
return unary_dp_impl_fn(src, dst, sycl_queue, depends)

super().__init__(
Expand Down Expand Up @@ -264,11 +266,12 @@ def _call_func(src1, src2, dst, sycl_queue, depends=None):
if depends is None:
depends = []

if mkl_fn_to_call is not None and mkl_fn_to_call(
sycl_queue, src1, src2, dst
):
# call pybind11 extension for binary function from OneMKL VM
return mkl_impl_fn(sycl_queue, src1, src2, dst, depends)
if vmi.mkl_vm_is_defined() and mkl_fn_to_call is not None:
if getattr(vmi, mkl_fn_to_call)(sycl_queue, src1, src2, dst):
# call pybind11 extension for binary function from OneMKL VM
return getattr(vmi, mkl_impl_fn)(
sycl_queue, src1, src2, dst, depends
)
return binary_dp_impl_fn(src1, src2, dst, sycl_queue, depends)

super().__init__(
Expand Down
Loading