Skip to content

Commit d7453ea

Browse files
Merge 57bb9a3 into 28d3348
2 parents 28d3348 + 57bb9a3 commit d7453ea

File tree

13 files changed

+1490
-82
lines changed

13 files changed

+1490
-82
lines changed

dpnp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ endfunction()
5656

5757
build_dpnp_cython_ext_with_backend(dparray ${CMAKE_CURRENT_SOURCE_DIR}/dparray.pyx dpnp)
5858
add_subdirectory(backend)
59+
add_subdirectory(backend/extensions/blas)
5960
add_subdirectory(backend/extensions/lapack)
6061
add_subdirectory(backend/extensions/vm)
6162
add_subdirectory(backend/extensions/sycl_ext)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2016-2023, Intel Corporation
3+
# All rights reserved.
4+
#
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+
#
13+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
# THE POSSIBILITY OF SUCH DAMAGE.
24+
# *****************************************************************************
25+
26+
27+
set(python_module_name _blas_impl)
28+
set(_module_src
29+
${CMAKE_CURRENT_SOURCE_DIR}/blas_py.cpp
30+
${CMAKE_CURRENT_SOURCE_DIR}/gemm.cpp
31+
${CMAKE_CURRENT_SOURCE_DIR}/gemm_batch.cpp
32+
)
33+
34+
pybind11_add_module(${python_module_name} MODULE ${_module_src})
35+
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
36+
37+
if (WIN32)
38+
if (${CMAKE_VERSION} VERSION_LESS "3.27")
39+
# this is a work-around for target_link_options inserting option after -link option, cause
40+
# linker to ignore it.
41+
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -fsycl-device-code-split=per_kernel")
42+
endif()
43+
endif()
44+
45+
set_target_properties(${python_module_name} PROPERTIES CMAKE_POSITION_INDEPENDENT_CODE ON)
46+
47+
target_include_directories(${python_module_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
48+
target_include_directories(${python_module_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
49+
50+
target_include_directories(${python_module_name} PUBLIC ${Dpctl_INCLUDE_DIRS})
51+
target_include_directories(${python_module_name} PUBLIC ${Dpctl_TENSOR_INCLUDE_DIR})
52+
53+
if (WIN32)
54+
target_compile_options(${python_module_name} PRIVATE
55+
/clang:-fno-approx-func
56+
/clang:-fno-finite-math-only
57+
)
58+
else()
59+
target_compile_options(${python_module_name} PRIVATE
60+
-fno-approx-func
61+
-fno-finite-math-only
62+
)
63+
endif()
64+
65+
target_link_options(${python_module_name} PUBLIC -fsycl-device-code-split=per_kernel)
66+
if (UNIX)
67+
# this option is support on Linux only
68+
target_link_options(${python_module_name} PUBLIC -fsycl-link-huge-device-code)
69+
endif()
70+
71+
if (DPNP_GENERATE_COVERAGE)
72+
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
73+
endif()
74+
75+
if (MKL_VERSION_2024)
76+
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::BLAS)
77+
else()
78+
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_DPCPP)
79+
endif()
80+
81+
install(TARGETS ${python_module_name}
82+
DESTINATION "dpnp/backend/extensions/blas"
83+
)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//*****************************************************************************
2+
// Copyright (c) 2023, Intel Corporation
3+
// All rights reserved.
4+
//
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+
//
13+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
// THE POSSIBILITY OF SUCH DAMAGE.
24+
//*****************************************************************************
25+
//
26+
// This file defines functions of dpnp.backend._lapack_impl extensions
27+
//
28+
//*****************************************************************************
29+
30+
#include <pybind11/pybind11.h>
31+
#include <pybind11/stl.h>
32+
33+
#include "gemm.hpp"
34+
35+
namespace blas_ext = dpnp::backend::ext::blas;
36+
namespace py = pybind11;
37+
38+
// populate dispatch tables
39+
void init_dispatch_tables(void)
40+
{
41+
blas_ext::init_gemm_batch_dispatch_table();
42+
blas_ext::init_gemm_dispatch_table();
43+
}
44+
45+
PYBIND11_MODULE(_blas_impl, m)
46+
{
47+
init_dispatch_tables();
48+
49+
{
50+
m.def("_gemm", &blas_ext::gemm,
51+
"Call `gemm` from OneMKL LAPACK library to return "
52+
"the matrix-matrix product with 2-D matrices.",
53+
py::arg("sycl_queue"), py::arg("matrixA"), py::arg("matrixB"),
54+
py::arg("result"), py::arg("depends") = py::list());
55+
}
56+
57+
{
58+
m.def("_gemm_batch", &blas_ext::gemm_batch,
59+
"Call `gemm_batch` from OneMKL LAPACK library to return "
60+
"the matrix-matrix product with general matrices.",
61+
py::arg("sycl_queue"), py::arg("matrixA"), py::arg("matrixB"),
62+
py::arg("result"), py::arg("m"), py::arg("n"), py::arg("k"),
63+
py::arg("batch_size"), py::arg("ld_array_1"),
64+
py::arg("ld_array_2"), py::arg("ld_result"), py::arg("stridea"),
65+
py::arg("strideb"), py::arg("stridec"), py::arg("transA_int"),
66+
py::arg("transB_int"), py::arg("depends") = py::list());
67+
}
68+
}

0 commit comments

Comments
 (0)