Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6974 Discussions

Combining Hadamard division and matrix multiplication in one procedure

Chris_Mayer
Beginner
834 Views

Hey everyone,

 

I am currently optimising code that performs a series of Hadamard (element-wise)  divisions (1 ./ matrix) and matrix multiplications.

 

For example:

 

C = A[1 ⊘ B]
1, B ∈ R^d×d
A ∈ R^d×d

 

 

Currently, I implement the calculation in two steps:

 

vdDiv(d*d, mOnes, B, temp_M);
// mOnes is a matrix with all elements equal 1

cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans,
                    d, d, d, alpha, A, d, temp_M, d, beta, C, d);

 

 

I want to avoid doing d^2+ d^3 operations and do instead just d^3 operations.

In theory, both steps could be performed in one procedure by defining C as:

 

(c_ij) = a_i1 / b_1j + a_2i / b_2j + ... + a_id / b_dj

 

 

Is there a way to implement this in MKL efficiently?

 

Many thanks and best,

Chris

0 Kudos
6 Replies
VidyalathaB_Intel
Moderator
785 Views

Hi Chris,


As we haven't heard back from you, could you please provide us with an update regarding your issue?


Regards,

Vidya.


0 Kudos
Chris_Mayer
Beginner
779 Views

Hi Vidya,

 

Thank you for your reply!

 

I could not find any function in the documentation that provides the operation that I am seeking. Could you point me to a specific function that might solve the problem?

 

Many thanks and best,

 

Chris

0 Kudos
VidyalathaB_Intel
Moderator
768 Views

Hi Chris,

 

The links in the earlier post lists out the routines which are extensions of BLAS that are available in MKL (i guess there is no direct routine available in MKL which combines both the cases hadamard division and gemm operation and as I mentioned you can refer to the extended functionalities of BLAS)

They may not exactly match the use case of yours but might help you for further stages.

Maybe using this function cblas-gemm-batch might help you but not sure https://www.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-c/top/blas-and-sparse-blas-routines/blas-like-extensions/cblas-gemm-batch.html

 

Regards,

Vidya.

 

0 Kudos
Chris_Mayer
Beginner
735 Views

Hi Vidya,

 

Thank you!

It seems that it is not possible to perform the exact operation that I envisioned. I will try to find a work around. The question is answered for me, thank you.

 

Best,

Chris

0 Kudos
VidyalathaB_Intel
Moderator
729 Views

Hi Chris,


>>The question is answered for me,

Thanks for the confirmation.

Please post a new question if you need any additional assistance from Intel as this thread will no longer be monitored.


Have a Nice Day!


Regards,

Vidya.


0 Kudos
Reply