Code generation from matlab function using my own BLAS function
Show older comments
codegen is by default replacing multiplication with cblas_sgemm though the header file have fun definition with different name.
What is the correct approach. I want to replace maths operators with BLAS?
classdef ifxcallback < coder.BLASCallback
methods (Static)
function updateBuildInfo(buildInfo, ~)
buildInfo.addSourceFiles(fullfile(pwd,'BLAS','src.c'))
buildInfo.addIncludePaths(fullfile(pwd,'BLAS'));
end
function headerName = getHeaderFilename()
headerName = 'inc.h';
end
function intTypeName = getBLASIntTypeName()
intTypeName = 'int';
end
end
end
function p = useEnumNameRatherThanTypedef()
p = true;
end
12 Comments
Ryan Livingston
on 26 Mar 2021
MATLAB Coder expects to call a BLAS library with a CBLAS interface. Which BLAS library are you using and what is the name of the cblas_sgemm analog in that library?
anamika kumari
on 26 Mar 2021
Edited: anamika kumari
on 26 Mar 2021
Ryan Livingston
on 26 Mar 2021
Ah. Coder isn't going to find the updated name as it is expecting to find a standard CBLAS library which doesn't contain cblas_sgemm_f32. Can you update the name in your library to be cblas_sgemm or add a wrapper to provide the standard CBLAS interface:
http://www.netlib.org/blas/cblas.h
anamika kumari
on 26 Mar 2021
anamika kumari
on 30 Mar 2021
Ryan Livingston
on 30 Mar 2021
MATLAB Coder may decide to use either cblas_sgemv or cblas_sgemm (I think it currently favors _sgemm) so the BLAS library would need to have both routines available.
anamika kumari
on 31 Mar 2021
Edited: anamika kumari
on 31 Mar 2021
Ryan Livingston
on 1 Apr 2021
We don't have an explicit list anywhere. The code that produces the BLAS calls is all under:
fullfile(matlabroot,'toolbox','eml','eml','+coder','+internal','+blas')
You'll see a bunch of MATLAB functions named similar to BLAS functions. Inside each you'll find the calls being used:
% Select BLAS function.
if isreal(C)
if isa(C, 'single')
fun = 'sgemm';
else
fun = 'dgemm';
end
else
if isa(C, 'single')
fun = 'cgemm';
else
fun = 'zgemm';
end
end
So using that, you should be able to extract the list.
Can I ask why you're developing the BLAS library and what hardware/target it's for? My expectation was that most hardware would have an existing BLAS library so I'm interested to hear what your team is working on.
anamika kumari
on 5 Apr 2021
Ryan Livingston
on 5 Apr 2021
Good to know. Thanks for the info.
Those are the BLAS functions being called via the CustomBLASCallback interface as of right now. I cannot confirm that if a new one is introduced it will also appear there. Being an internal directory, we assume that we're free to refactor at will. So that code may be moved, split, etc. in future releases.
If it would be helpful for you to have a curated list, I can put in an internal request to see if the teams would consider documenting such a list in the future. I can't promise it will be agreed to, but we could at least ask.
anamika kumari
on 6 Apr 2021
anamika kumari
on 20 Apr 2021
Edited: anamika kumari
on 21 Apr 2021
Answers (0)
Categories
Find more on Algorithm Design Basics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!