Skip to content

Commit 8b5f3b6

Browse files
Add new blas extension and update matmul impl
1 parent 83d28d7 commit 8b5f3b6

File tree

7 files changed

+639
-43
lines changed

7 files changed

+639
-43
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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
)
32+
33+
pybind11_add_module(${python_module_name} MODULE ${_module_src})
34+
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
35+
36+
if (WIN32)
37+
if (${CMAKE_VERSION} VERSION_LESS "3.27")
38+
# this is a work-around for target_link_options inserting option after -link option, cause
39+
# linker to ignore it.
40+
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -fsycl-device-code-split=per_kernel")
41+
endif()
42+
endif()
43+
44+
set_target_properties(${python_module_name} PROPERTIES CMAKE_POSITION_INDEPENDENT_CODE ON)
45+
46+
target_include_directories(${python_module_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
47+
target_include_directories(${python_module_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
48+
49+
target_include_directories(${python_module_name} PUBLIC ${Dpctl_INCLUDE_DIRS})
50+
target_include_directories(${python_module_name} PUBLIC ${Dpctl_TENSOR_INCLUDE_DIR})
51+
52+
if (WIN32)
53+
target_compile_options(${python_module_name} PRIVATE
54+
/clang:-fno-approx-func
55+
/clang:-fno-finite-math-only
56+
)
57+
else()
58+
target_compile_options(${python_module_name} PRIVATE
59+
-fno-approx-func
60+
-fno-finite-math-only
61+
)
62+
endif()
63+
64+
target_link_options(${python_module_name} PUBLIC -fsycl-device-code-split=per_kernel)
65+
if (UNIX)
66+
# this option is support on Linux only
67+
target_link_options(${python_module_name} PUBLIC -fsycl-link-huge-device-code)
68+
endif()
69+
70+
if (DPNP_GENERATE_COVERAGE)
71+
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
72+
endif()
73+
74+
if (MKL_VERSION_2024)
75+
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::BLAS)
76+
else()
77+
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_DPCPP)
78+
endif()
79+
80+
install(TARGETS ${python_module_name}
81+
DESTINATION "dpnp/backend/extensions/blas"
82+
)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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_dispatch_table();
42+
}
43+
44+
PYBIND11_MODULE(_blas_impl, m)
45+
{
46+
init_dispatch_tables();
47+
48+
m.def("_gemm", &blas_ext::gemm,
49+
"Call `gemm` from OneMKL LAPACK library to return "
50+
"the matrix-matrix product with general matrices.",
51+
py::arg("sycl_queue"), py::arg("matrixA"), py::arg("matrixB"),
52+
py::arg("matrixC"), py::arg("depends") = py::list());
53+
}

0 commit comments

Comments
 (0)