Skip to content

Add new blas extension and update dpnp.matmul func - #1616

Merged
vtavana merged 25 commits into
masterfrom
update_matmul
Jan 13, 2024
Merged

Add new blas extension and update dpnp.matmul func#1616
vtavana merged 25 commits into
masterfrom
update_matmul

Conversation

@vlad-perevezentsev

@vlad-perevezentsevvlad-perevezentsev commented Nov 3, 2023

Copy link
Copy Markdown
Contributor

This PR updates dpnp.matmul implementation with gemm function call from oneapi::mkl::blas added to dpnp.backend.extensions.blas.
In addition, gemm_batch function is also added which is the batched versions of gemm, performing multiple gemm operations in a single call.
The implementation is written as a pybind11 extension above required BLAS functions.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • If this PR is a work in progress, are you filing the PR as a draft?

@github-actions

github-actionsBot commented Nov 3, 2023

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/index.html

@vtavana
vtavana marked this pull request as ready for review November 30, 2023 20:07
@npolina4
npolina4 self-requested a review December 7, 2023 20:03

@npolina4npolina4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result does not match with numpy

importnumpy, dpnpdefinit():
N=5A=numpy.empty((N, N), dtype=numpy.float32)
foriinrange(N):
A[i, : i+1] =numpy.fromfunction(lambdaj: (-j%N) /N+1, (i+1,))
A[i, i+1 :] =0.0A[i, i+1 :] =0.0returnAdefkernel(A):
foriinrange(A.shape[0]):
forjinrange(i):
A[i, j] -=A[i, :j] @ A[:j, j]
a=init()
b=dpnp.asarray(a)
kernel(a)
kernel(b)
print(a-b.asnumpy())
[[0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. ]
[0. 0. 0. 1.6 0. ]]

Comment threaddpnp/backend/extensions/blas/blas_py.cpp Outdated
Comment threaddpnp/backend/extensions/blas/blas_py.cpp Outdated
Comment threaddpnp/backend/extensions/blas/blas_py.cpp Outdated
Comment threaddpnp/backend/extensions/blas/gemm.cpp Outdated
Comment threaddpnp/backend/extensions/blas/gemm.cpp Outdated
Comment threaddpnp/backend/extensions/blas/types_matrix.hpp
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threadtests/third_party/cupy/math_tests/test_matmul.py Outdated
Comment threaddpnp/backend/extensions/blas/blas_py.cpp Outdated
Comment threaddpnp/backend/extensions/blas/gemm_batch.cpp
Comment threaddpnp/backend/extensions/blas/gemm_batch.cpp Outdated
Comment threaddpnp/backend/extensions/blas/gemm_batch.cpp Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threadtests/test_mathematical.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threadtests/test_mathematical.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/backend/extensions/blas/gemm.cpp Outdated
Comment threaddpnp/backend/extensions/blas/gemm.cpp
Comment threaddpnp/backend/extensions/blas/gemm.cpp Outdated
Comment threaddpnp/backend/extensions/blas/gemm.cpp
Comment threaddpnp/backend/extensions/blas/gemm_batch.cpp
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threaddpnp/dpnp_iface_linearalgebra.py Outdated
Comment threadtests/test_mathematical.py
Comment threaddpnp/dpnp_utils/dpnp_utils_linearalgebra.py
Comment threaddpnp/dpnp_utils/dpnp_utils_linearalgebra.py Outdated
Comment threaddpnp/dpnp_utils/dpnp_utils_linearalgebra.py Outdated
Comment threaddpnp/dpnp_utils/dpnp_utils_linearalgebra.py Outdated
Comment threaddpnp/dpnp_utils/dpnp_utils_linearalgebra.py
Comment threaddpnp/dpnp_utils/dpnp_utils_linearalgebra.py Outdated
Comment threaddpnp/dpnp_utils/dpnp_utils_linearalgebra.py Outdated
Comment threaddpnp/dpnp_utils/dpnp_utils_linearalgebra.py
Comment threaddpnp/dpnp_utils/dpnp_utils_linearalgebra.py Outdated
Comment threadtests/test_manipulation.py

@antonwolfyantonwolfy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @vtavana !

@vtavana
vtavana merged commit f95ceb9 into masterJan 13, 2024
@vtavana
vtavana deleted the update_matmul branch January 13, 2024 01:49
github-actionsBot added a commit that referenced this pull request Jan 13, 2024
* Add new blas extension and update matmul impl
* Add support for N-D array
add N-dimension
* support more special cases + add new tests
* fix random behavior on cpu
* correct dtypes + support more keywords
* add strided support
* check input arrays
* address comments - first round
* address comments - second round
* address comments - third round
* fix pre-commit
* improve test coverage
* address comments
* update _gemm_res_dtype func
* fix a test for result_type
* fix minor issues
* skip tests for matmul
---------
Co-authored-by: Vahid Tavanashad <vahid.tavanashad@intel.com>
Co-authored-by: vtavana <120411540+vtavana@users.noreply.github.com>
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com> f95ceb9
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@vlad-perevezentsev@npolina4@antonwolfy@vtavana