Skip to content

Implement build for NVIDIA GPU #1926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
56 changes: 56 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,62 @@ 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
)
option(DPNP_USE_ONEMKL_INTERFACES
"Build DPNP with oneMKL Interfaces"
OFF
)
set(_dpnp_sycl_targets)
set(_use_onemkl_interfaces_cuda OFF)
if ("x${DPNP_SYCL_TARGETS}" STREQUAL "x")
if(DPNP_TARGET_CUDA)
set(_dpnp_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
set(_use_onemkl_interfaces_cuda ON)
else()
if(DEFINED ENV{DPNP_TARGET_CUDA})
set(_dpnp_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
set(_use_onemkl_interfaces_cuda ON)
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()

set(_use_onemkl_interfaces OFF)
if(DPNP_USE_ONEMKL_INTERFACES)
set(_use_onemkl_interfaces ON)
else()
if(DEFINED ENV{DPNP_USE_ONEMKL_INTERFACES})
set(_use_onemkl_interfaces ON)
endif()
endif()

if(_use_onemkl_interfaces)
set(BUILD_FUNCTIONAL_TESTS False)
set(BUILD_EXAMPLES False)
if(_use_onemkl_interfaces_cuda)
# set(ENABLE_CUBLAS_BACKEND True)
set(ENABLE_CUSOLVER_BACKEND True)
set(ENABLE_CUFFT_BACKEND True)
# set(ENABLE_CURAND_BACKEND True)
set(ENABLE_MKLGPU_BACKEND False)
set(ENABLE_MKLCPU_BACKEND False)
endif()
FetchContent_Declare(
onemkl_interfaces_library
GIT_REPOSITORY https://github.com/oneapi-src/oneMKL.git
GIT_TAG f2d2dcb4213a435bb60fbb88320c5f24892423ce
)
FetchContent_MakeAvailable(onemkl_interfaces_library)
endif()

if(WIN32)
string(CONCAT WARNING_FLAGS
"-Wall "
Expand Down
21 changes: 20 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,12 @@ 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(_use_onemkl_interfaces)
target_link_libraries(${python_module_name} PUBLIC onemkl)
target_compile_options(${python_module_name} PRIVATE -DUSE_ONEMKL_INTERFACES)
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
36 changes: 22 additions & 14 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()
{
// TODO: replace when MKLD-10506 is implemented
// mkl_dft::config_value placement;
#if defined(USE_ONEMKL_INTERFACES)
mkl_dft::config_value placement;
descr_.get_value(mkl_dft::config_param::PLACEMENT, &placement);
return (placement == mkl_dft::config_value::INPLACE);
#else
// TODO: remove branch when MKLD-10506 is implemented
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 // USE_ONEMKL_INTERFACES
}

void set_in_place(const bool &in_place_request)
{
// 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);
#if defined(USE_ONEMKL_INTERFACES)
descr_.set_value(mkl_dft::config_param::PLACEMENT,
(in_place_request)
? mkl_dft::config_value::INPLACE
: mkl_dft::config_value::NOT_INPLACE);
#else
// TODO: remove branch when MKLD-10506 is implemented
descr_.set_value(mkl_dft::config_param::PLACEMENT,
(in_place_request)
? DFTI_CONFIG_VALUE::DFTI_INPLACE
: DFTI_CONFIG_VALUE::DFTI_NOT_INPLACE);
#endif // USE_ONEMKL_INTERFACES
}

// config_param::PRECISION
Expand All @@ -221,14 +227,16 @@ class DescriptorWrapper
// config_param::COMMIT_STATUS
bool is_committed()
{
// TODO: replace when MKLD-10506 is implemented
// mkl_dft::config_value committed;
#if defined(USE_ONEMKL_INTERFACES)
mkl_dft::config_value committed;
descr_.get_value(mkl_dft::config_param::COMMIT_STATUS, &committed);
return (committed == mkl_dft::config_value::COMMITTED);
#else
// TODO: remove branch when MKLD-10506 is implemented
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 // USE_ONEMKL_INTERFACES
}

private:
Expand Down
2 changes: 1 addition & 1 deletion dpnp/backend/extensions/fft/out_of_place.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// THE POSSIBILITY OF SUCH DAMAGE.
//*****************************************************************************

#include <oneapi/mkl/dfti.hpp>
#include <oneapi/mkl.hpp>
#include <sycl/sycl.hpp>

#include <dpctl4pybind11.hpp>
Expand Down
21 changes: 20 additions & 1 deletion dpnp/backend/extensions/lapack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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 @@ -85,7 +99,12 @@ 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(_use_onemkl_interfaces)
target_link_libraries(${python_module_name} PUBLIC onemkl)
target_compile_options(${python_module_name} PRIVATE -DUSE_ONEMKL_INTERFACES)
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 @@ -56,6 +56,11 @@ static sycl::event gesv_impl(sycl::queue &exec_q,
char *in_b,
const std::vector<sycl::event> &depends)
{
#if defined(USE_ONEMKL_INTERFACES)
// Temporary flag for build only
// FIXME: Need to implement by using lapack::getrf and lapack::getrs
std::logic_error("Not Implemented");
#else
type_utils::validate_type_for_device<T>(exec_q);

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

return ht_ev;
#endif // USE_ONEMKL_INTERFACES
}

std::pair<sycl::event, sycl::event>
Expand Down
88 changes: 47 additions & 41 deletions dpnp/backend/extensions/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,49 @@
# 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}/nextafter.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 _use_onemkl_interfaces)
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}/nextafter.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 @@ -112,7 +114,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::VM)
if(_use_onemkl_interfaces)
target_compile_options(${python_module_name} PRIVATE -DUSE_ONEMKL_INTERFACES)
else()
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::VM)
endif()

install(TARGETS ${python_module_name}
DESTINATION "dpnp/backend/extensions/vm"
Expand Down
18 changes: 17 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 not defined(USE_ONEMKL_INTERFACES)
#include "abs.hpp"
#include "acos.hpp"
#include "acosh.hpp"
Expand Down Expand Up @@ -68,9 +69,13 @@
#include "trunc.hpp"

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

#include <pybind11/pybind11.h>

PYBIND11_MODULE(_vm_impl, m)
{
#if not defined(USE_ONEMKL_INTERFACES)
vm_ns::init_abs(m);
vm_ns::init_acos(m);
vm_ns::init_acosh(m);
Expand Down Expand Up @@ -110,4 +115,15 @@ PYBIND11_MODULE(_vm_impl, m)
vm_ns::init_tan(m);
vm_ns::init_tanh(m);
vm_ns::init_trunc(m);
#endif // USE_ONEMKL_INTERFACES
m.def(
"_is_available",
[](void) {
#if defined(USE_ONEMKL_INTERFACES)
return false;
#else
return true;
#endif // USE_ONEMKL_INTERFACES
},
"Check if the OneMKL VM library can be used.");
}
Loading
Loading