-
Notifications
You must be signed in to change notification settings - Fork 973
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
Clarification Needed on Memory Requirements for Batch Matrix Multiplication Description #1979
Comments
@IshitaShreya, oneDNN does not have |
It is understood that for batched matrix multiplication, matrices must be provided as memory objects with at least 3 dimensions. However, I am interested in knowing if I can pass non-contiguous memory blocks for each batch of matrices. 1. Contiguous Memory Block Example: // Allocate contiguous memory blocks for matrices A, B, and C 2. Non-Contiguous Memory Block Example: // Vectors of pointers to individual matrices Questions |
@IshitaShreya, oneDNN memory objects use contiguous memory blocks. Please refer to the memory object section of the API reference. |
I am using oneDNN's batch matrix multiplication (batchmatmul) to perform three matrix multiplication operations. I need clarification on whether all the matrix elements must be passed as contiguous memory for the function to work correctly.
Question
For performing three matrix multiplication operations with batchmatmul, do we need to pass all matrices as a contiguous memory block, or can we use separate pointers for each matrix?
Context
https://oneapi-src.github.io/oneDNN/page_matmul_example_cpp.html#doxid-matmul-example-cpp
Here are the two scenarios I am considering:
1. Contiguous Memory Block:
Allocate a single memory block for all matrices. I combine all elements of matrices A, B, and C into single contiguous memory blocks (combined_A, combined_B, combined_C).
Example code:
// Allocate contiguous memory blocks for matrices A, B, and C
float *combined_A = new float[sizeA1 + sizeA2 + sizeA3];
float *combined_B = new float[sizeB1 + sizeB2 + sizeB3];
float *combined_C = new float[sizeC1 + sizeC2 + sizeC3];
// Perform batch matrix multiplication
batchmatmul(combined_A, combined_B, combined_C, ...); // This works
2. Separate Pointers:
Allocate separate memory blocks for each matrix.
Example code:
// Vectors of pointers to individual matrices
std::vector<float *> vecA = {ptrA1, ptrA2, ptrA3};
std::vector<float *> vecB = {ptrB1, ptrB2, ptrB3};
std::vector<float *> vecC = {ptrC1, ptrC2, ptrC3};
// Perform batch matrix multiplication
batchmatmul(vecA.data(), vecB.data(), vecC.data(), ...); //Clarification on this
Additional Information
If using separate pointers is supported, any guidelines or examples on how to correctly set up and pass these pointers to the batchmatmul function would be greatly appreciated.
The text was updated successfully, but these errors were encountered: