Code generation from matlab function using my own BLAS function
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Ryan Livingston
2021-3-26
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
2021-3-26
编辑:anamika kumari
2021-3-26
@Ryan LivingstonI have created dummy BLAS Library and the name analogus to cblas_sgemm is cblas_sgemm_f32.
classdef ifxBLAS < coder.BLASCallback
methods (Static)
function updateBuildInfo(buildInfo, ~)
libPath = fullfile(pwd,'BLAS');
libPriority = '';
libPreCompiled = true;
libLinkOnly = true;
libs = {'src.lib'};
buildInfo.addLinkObjects(libs, libPath, libPriority, libPreCompiled, libLinkOnly);
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
Ryan Livingston
2021-3-26
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
2021-3-30
@Ryan Livingston My library have definition for matrix-vector multiplication(cblas-sgemv) but my matlab function of matrix-vector multiplication is getting encoded to cblas-sgemm.
Can you guide me with this?
function E = func(A,B,C) %A,B are matrices and C is a vector
%Matrix mul
D = A*B;
E = D*C;
end
Ryan Livingston
2021-3-30
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
2021-3-31
编辑:anamika kumari
2021-3-31
@Ryan Livingston Hi Ryan. Can you provide the list of BLAS functions used by the code generator? we need this list for development of a BLAS library, we will prioritize development of those functions used by matlab coder and develop the rest later.
Ryan Livingston
2021-4-1
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
2021-4-5
@Ryan Livingston Thank you Ryan for the clarification.
We are developing library for a vector processor heavily optimized for performance using special language extensions supported by processor compiler.
Can you please confirm that the BLAS functions listed under fullfile(matlabroot,'toolbox','eml','eml','+coder','+internal','+blas') are the only ones that are today called by the matlab coder? And when support for a new BLAS function is introduced, one may expect to find corresponding .m file of the new function in this very folder?
Ryan Livingston
2021-4-5
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
2021-4-6
@Ryan Livingston Thank you very much for the proposal to raise an internal request. I, like many others are certain to find the curated list extraordinarily helpful. It helps prioritizing development activities.
Thanks a lot, again.
anamika kumari
2021-4-20
编辑:anamika kumari
2021-4-21
@Ryan Livingston Assuming that a sequence of mathematical operation have been described using simulink operators (e.g. multiply, add, transpose), it should be possible to generate either a BLAS call or perhaps a call to a function defined in the code replacement library. In a specific case such as matrix multiply, it should be possible for code generator to either generate cblas_sgemm() or crl_matrix_multiply(). Given availability of two alternative definitions, is it possible to prioritize one code replacement style over other?
For e.g. can i get code for operator matrix multiplication mapped to BLAS function while getting the code for the matrix transpose operator mapped to function defined in code replacement library?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with GPU Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)