Skip to content

Replace oneMKL with oneMath #5

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "steps/kernel_density_estimation_cpp/argparse"]
path = steps/kernel_density_estimation_cpp/argparse
url = https://github.com/p-ranav/argparse
[submodule "steps/mkl_interface/oneMKL"]
path = steps/mkl_interface/oneMKL
url = https://github.com/oneapi-src/oneMKL
[submodule "steps/mkl_interface/oneMath"]
path = steps/mkl_interface/oneMath
url = https://github.com/uxlfoundation/oneMath
2 changes: 1 addition & 1 deletion steps/mkl_interface/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python data-parallel native extension

Here we build Python extension for a QR decomposition using `oneMKL` LAPACK routines.
Here we build Python extension for a QR decomposition using `oneMath` LAPACK routines.

## Building

Expand Down
30 changes: 15 additions & 15 deletions steps/mkl_interface/building.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# oneMKL Interface
# oneMath Interface

[oneMKL Interfaces](https://github.com/oneapi-src/oneMKL) is an open-source implementation of the oneMKL Data Parallel C++ (DPC++) interface according to the [oneMKL specification](https://spec.oneapi.com/versions/latest/elements/oneMKL/source/index.html). It works with multiple devices (backends) using device-specific libraries underneath.
[oneMath Interfaces](https://github.com/uxlfoundation/oneMath) is an open-source implementation of the oneMath Data Parallel C++ (DPC++) interface according to the [oneMath specification](https://oneapi-spec.uxlfoundation.org/specifications/oneapi/latest/elements/onemath/source). It works with multiple devices (backends) using device-specific libraries underneath.

oneMKL is part of the [UXL Foundation](http://www.uxlfoundation.org/).
oneMath is part of the [UXL Foundation](http://www.uxlfoundation.org/).

## Getting the library

The library can be cloned from GitHub:

```bash
git clone https://github.com/oneapi-src/oneMKL.git
git clone https://github.com/uxlfoundation/oneMath.git
```

but it is also included in this repo as a git submodule, in "./oneMKL" subfolder.
but it is also included in this repo as a git submodule, in "./oneMath" subfolder.

## Building

oneMKL interface library allows for many ways to be built, please see [building oneMKL interface](https://oneapi-src.github.io/oneMKL/building_the_project_with_dpcpp.html) for full details.
oneMath interface library allows for many ways to be built, please see [building oneMath interface](https://uxlfoundation.github.io/oneMath/building_the_project_with_dpcpp.html) for full details.

Note that building oneMKL interfaces requires cmake, which may also be required to build the extension or dpctl (if targeting NVidia(R)). As such, it may be a good idea to install requirements for the chosen build path ([`scikit-build-core`](#building-c-extension-using-scikit-build-core) or [`meson-python`](#building-c-extension-using-meson-python)) ahead of time.
Note that building oneMath interfaces requires cmake, which may also be required to build the extension or dpctl (if targeting NVidia(R)). As such, it may be a good idea to install requirements for the chosen build path ([`scikit-build-core`](#building-c-extension-using-scikit-build-core) or [`meson-python`](#building-c-extension-using-meson-python)) ahead of time.

In order to target Intel(R) GPUs, CPUs, and NVidia(R) GPUs for BLAS, LAPACK, FFT, and RNG domains configure it as follows:

Expand Down Expand Up @@ -61,15 +61,15 @@ cd ..
A set of examples is included with the library. Let's build an LAPACK example of
solving general triangular linear system. We use `-fsycl-targets`
to specify targets to generate offload sections for, and link to the
library dynamically using `-lonemkl`:
library dynamically using `-lonemath`:

```bash
cd examples/lapack/run_time_dispatching/
icpx -fsycl getrs_usm.cpp \
-fsycl-targets=nvptx64-nvidia-cuda,spir64-unknown-unknown \
-I${MKL_INTERFACE_ROOT}/include \
-I${MKL_INTERFACE_ROOT}/../examples/include \
-L${MKL_INTERFACE_ROOT}/lib -lonemkl \
-L${MKL_INTERFACE_ROOT}/lib -lonemath \
-Wl,-rpath,${MKL_INTERFACE_ROOT}/lib -o run
```

Expand Down Expand Up @@ -153,11 +153,11 @@ See the [`dpctl` documentation](https://intelpython.github.io/dpctl/latest/begin

### Building C++ extension manually

We chose to demonstrate use of oneMKL interface library from Python by building
We chose to demonstrate use of oneMath interface library from Python by building
pybind11 extension that computes QR decomposition for a stack of real
floating-point matrices.

Since oneMKL LAPACK functions [require](https://spec.oneapi.io/versions/latest/elements/oneMKL/source/domains/lapack/lapack.html)
Since oneMath LAPACK functions [require](https://oneapi-spec.uxlfoundation.org/specifications/oneapi/latest/elements/onemath/source/domains/lapack/lapack)
column-major layout and modify input arrays in place, the extension must copy the input stack of matrices accordingly.

If requirements are not installed, install requirements.
Expand All @@ -178,14 +178,14 @@ Now build and install
icpx -fsycl -fPIC -shared -fno-approx-func -fno-fast-math \
$(python -m pybind11 --includes) -I$MKL_INTERFACE_ROOT/include \
$(python -m dpctl --includes) $(python -m dpctl --tensor-includes) \
-L$MKL_INTERFACE_ROOT/lib -lonemkl -Wl,-rpath,$MKL_INTERFACE_ROOT/lib \
-L$MKL_INTERFACE_ROOT/lib -lonemath -Wl,-rpath,$MKL_INTERFACE_ROOT/lib \
src/py.cpp -o mkl_interface_ext/_qr.so
```

Tests of the extension can be executed as follows:

```bash
# work-around a problem with oneMKL library linkage
# work-around a problem with oneMath library linkage
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${MKL_INTERFACE_ROOT}/lib
PYTHONPATH=$PYTHONPATH:$(pwd)/mkl_interface_ext pytest tests
```
Expand All @@ -209,8 +209,8 @@ pip install -r scikit_build_core_mkl_ext/requirements.txt
Now build and install

```bash
# help cmake to find oneMKL library
export ONEMKL_ROOT=$MKL_INTERFACE_ROOT
# help cmake to find oneMath library
export ONEMATH_ROOT=$MKL_INTERFACE_ROOT
# help cmake to find dpctl package if built in-place
export Dpctl_ROOT=$(python -m dpctl --cmakedir)
export VERBOSE=1
Expand Down
2 changes: 1 addition & 1 deletion steps/mkl_interface/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: mkl-ext
channels:
- conda-forge
- intel
- https://software.repos.intel.com/python/conda/
dependencies:
- python
- dpctl
Expand Down
2 changes: 1 addition & 1 deletion steps/mkl_interface/meson_mkl_ext/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: mkl-ext
channels:
- conda-forge
- intel
- https://software.repos.intel.com/python/conda/
dependencies:
- python
- dpctl
Expand Down
4 changes: 2 additions & 2 deletions steps/mkl_interface/meson_mkl_ext/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ if not pybind11_dep.found()
pybind11_dep = pybind11_proj.get_variable('pybind11_dep')
endif

mkl_dir = fs.parent(meson.current_source_dir()) + '/oneMKL'
mkl_dir = fs.parent(meson.current_source_dir()) + '/oneMath'
mkl_lib_dir = mkl_dir + '/install/lib'
mkl_lib = compiler.find_library('onemkl', dirs: mkl_lib_dir)
mkl_lib = compiler.find_library('onemath', dirs: mkl_lib_dir)
mkl_incl_dir = mkl_dir + '/install/include'
mkl_incl = include_directories(mkl_incl_dir)

Expand Down
2 changes: 1 addition & 1 deletion steps/mkl_interface/meson_mkl_ext/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ requires = [
[project]
name = "mkl_interface_ext"
version = "0.0.1"
description="An example of a pybind11 extension for dpctl using oneMKL interface library"
description="An example of a pybind11 extension for dpctl using oneMath interface library"
authors=[
{name = "Oleksandr Pavlyk", email="[email protected]"},
{name = "Nikita Grigorian", email="[email protected]"}
Expand Down
2 changes: 1 addition & 1 deletion steps/mkl_interface/mkl_interface_ext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ._qr_impl import qr

__doc__ = """
Sample Python extension built with oneAPI DPC++ and oneMKL interface library
Sample Python extension built with oneAPI DPC++ and oneMath interface library
prepared for SciPy 2024 poster
'Portable data-parallel native Python extensions with oneAPI'
by Nikita Grigorian and Oleksandr Pavlyk, Intel Corp.
Expand Down
2 changes: 1 addition & 1 deletion steps/mkl_interface/mkl_interface_ext/_qr_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class QRDecompositionResult(NamedTuple):
def qr(x : dpt.usm_ndarray) -> tuple[dpt.usm_ndarray, dpt.usm_ndarray]:
"""
Compute QR decomposition for a stack of matrices using
oneMKL interface library calls.
oneMath interface library calls.
"""
if not isinstance(x, dpt.usm_ndarray):
raise TypeError(
Expand Down
1 change: 0 additions & 1 deletion steps/mkl_interface/oneMKL
Submodule oneMKL deleted from 577a27
1 change: 1 addition & 0 deletions steps/mkl_interface/oneMath
Submodule oneMath added at 5c7e1e
6 changes: 3 additions & 3 deletions steps/mkl_interface/scikit_build_core_mkl_ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.27...3.29 FATAL_ERROR)
project(${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES CXX
DESCRIPTION "A sample pybind11 extension using portable oneMKL interface library"
DESCRIPTION "A sample pybind11 extension using portable oneMath interface library"
)

option(TARGET_CUDA "Whether to additionally target NVPTX64" OFF)
Expand Down Expand Up @@ -31,7 +31,7 @@ FetchContent_MakeAvailable(pybind11)

find_package(Dpctl CONFIG REQUIRED)

find_package(oneMKL CONFIG REQUIRED)
find_package(oneMath CONFIG REQUIRED)

set(py_module_name _qr)
set(_mkl_iface_ext_sources
Expand All @@ -47,7 +47,7 @@ target_compile_options(${py_module_name} PRIVATE -O3 -fno-approx-func -fno-fast-
target_include_directories(${py_module_name} PRIVATE ${Dpctl_INCLUDE_DIRS})
target_include_directories(${py_module_name} PRIVATE ${Dpctl_TENSOR_INCLUDE_DIR})

target_link_libraries(${py_module_name} PRIVATE MKL::onemkl)
target_link_libraries(${py_module_name} PRIVATE ONEMATH::onemath)

set(_sycl_targets)
set(_hip_targets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: mkl-ext
channels:
- conda-forge
- intel
- https://software.repos.intel.com/python/conda/
dependencies:
- python
- dpctl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ requires = [
[project]
name = "mkl_interface_ext"
version = "0.0.1"
description="An example of a pybind11 extension for dpctl using oneMKL interface library"
description="An example of a pybind11 extension for dpctl using oneMath interface library"
authors=[
{name = "Oleksandr Pavlyk", email="[email protected]"},
{name = "Nikita Grigorian", email="[email protected]"}
Expand Down
14 changes: 7 additions & 7 deletions steps/mkl_interface/src/py.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <sycl/sycl.hpp>
#include "oneapi/mkl.hpp"
#include "oneapi/math.hpp"

#include <cstdint>
#include <exception>
Expand Down Expand Up @@ -61,10 +61,10 @@ do_qr(
std::int64_t n_linear_streams = (b > 16) ? 4 : ((b > 4 ? 2 : 1));

std::int64_t scratch_sz_geqrf =
oneapi::mkl::lapack::geqrf_scratchpad_size<T>(exec_q, m, n, lda);
oneapi::math::lapack::geqrf_scratchpad_size<T>(exec_q, m, n, lda);

std::int64_t scratch_sz_orgqr =
oneapi::mkl::lapack::orgqr_scratchpad_size<T>(exec_q, m, m, tau_size, lda);
oneapi::math::lapack::orgqr_scratchpad_size<T>(exec_q, m, m, tau_size, lda);

std::int64_t padding = 256 / sizeof(T);
size_t alloc_tau_sz = round_up_mult(n_linear_streams * tau_size, padding);
Expand Down Expand Up @@ -106,9 +106,9 @@ do_qr(
// overwrites memory in current_a
sycl::event e_geqrf;
try {
e_geqrf = oneapi::mkl::lapack::geqrf(
e_geqrf = oneapi::math::lapack::geqrf(
exec_q, m, n, current_a, lda, current_tau, current_scratch_geqrf, scratch_sz_geqrf, current_dep);
} catch (const oneapi::mkl::lapack::exception &e) {
} catch (const oneapi::math::lapack::exception &e) {
std::cerr << "Exception raised by geqrf: " << e.what() << ", info = " << e.info() << std::endl;

e_ptr = std::current_exception();
Expand Down Expand Up @@ -152,9 +152,9 @@ do_qr(

sycl::event e_orgqr;
try {
e_orgqr = oneapi::mkl::lapack::orgqr(
e_orgqr = oneapi::math::lapack::orgqr(
exec_q, m, m, tau_size, current_q, lda, current_tau, current_scratch_orgqr, scratch_sz_orgqr, {e_copy_q});
} catch (const oneapi::mkl::lapack::exception &e) {
} catch (const oneapi::math::lapack::exception &e) {
std::cerr << "Exception raised by orgqr: " << e.what() << ", info = " << e.info() << std::endl;

e_ptr = std::current_exception();
Expand Down
2 changes: 1 addition & 1 deletion steps/sycl_python_extension/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: kde-ext
channels:
- conda-forge
- intel
- https://software.repos.intel.com/python/conda/
dependencies:
- python
- dpctl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: kde-ext
channels:
- conda-forge
- intel
- https://software.repos.intel.com/python/conda/
dependencies:
- python
- dpctl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: kde-ext
channels:
- conda-forge
- intel
- https://software.repos.intel.com/python/conda/
dependencies:
- python
- cython
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: kde-ext
channels:
- conda-forge
- intel
- https://software.repos.intel.com/python/conda/
dependencies:
- python
- dpctl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: kde-ext
channels:
- conda-forge
- intel
- https://software.repos.intel.com/python/conda/
dependencies:
- python
- cython
Expand Down