coder.BLASCallback - Abstract class for specifying the BLAS library and CBLAS header and data type

  information for BLAS calls in generated code - MATLAB ([original](https://www.mathworks.com/help/coder/ref/coder.blascallback-class.html)) ([raw](?raw))

Namespace: coder

Abstract class for specifying the BLAS library and CBLAS header and data type information for BLAS calls in generated code

Description

coder.BLASCallback is an abstract class for defining a BLAS callback class. A BLAS callback class specifies the BLAS library and CBLAS header and data type information to use for BLAS calls in code generated from MATLAB® code. If you use MATLAB Coder™ to generate standalone code or generate code for the MATLAB Function block, for certain vector and matrix function calls, you can generate BLAS calls. To generate BLAS calls, set the appropriate configuration parameter to the name of the BLAS callback class.

To define a BLAS callback class with the name useMyBLAS, make the following line the first line of your class definition file.

classdef useMyBLAS < coder.BLASCallback

You must define the updateBuildInfo, getHeaderFileName, andgetBLASIntTypeName methods. The other methods,getBLASDoubleComplexTypeName,getBLASSingleComplexTypeName, anduseEnumNameRatherThanTypedef, are already implemented incoder.BLASCallback. In certain situations, you must override these methods with your own definitions when you define your callback class. All methods are static and are not compiled.

Methods

Examples

collapse all

Callback Class for Intel MKL BLAS

This example is an implementation of the BLAS callback classmklcallback for linking to the Intel MKL BLAS library on a Windows® platform. mklcallback does not include explicit implementations of getBLASDoubleComplexTypeName,getBLASSingleComplexTypeName, anduseEnumNameRatherThanTypedef. It inherits these methods fromcoder.BLASCallback.

classdef mklcallback < coder.BLASCallback methods (Static) function updateBuildInfo(buildInfo, ~) libPath = fullfile(pwd,'mkl','WIN','lib','intel64'); libPriority = ''; libPreCompiled = true; libLinkOnly = true; libs = {'mkl_intel_ilp64.lib' 'mkl_intel_thread.lib' 'mkl_core.lib'}; buildInfo.addLinkObjects(libs, libPath, libPriority, libPreCompiled, libLinkOnly); buildInfo.addLinkObjects('libiomp5md.lib',fullfile(matlabroot,'bin','win64'), ... libPriority, libPreCompiled, libLinkOnly); buildInfo.addIncludePaths(fullfile(pwd,'mkl','WIN','include')); buildInfo.addDefines('-DMKL_ILP64'); end function headerName = getHeaderFilename() headerName = 'mkl_cblas.h'; end function intTypeName = getBLASIntTypeName() intTypeName = 'MKL_INT'; end end end

Use this example class as a template for writing your own BLAS callback class.

If you are using a different BLAS library, replace 'mkl_cblas.h' with the name of your CBLAS header file.

If you are using a different BLAS library, replace 'MKL_INT' with the name of your CBLAS integer data type.

To update the build information in updateBuildInfo with the name and location of your BLAS library, use the build informationaddLinkObjects method. If you use the Intel MKL BLAS library, use the link line advisor to see which libraries and compiler options are recommended for your use case.

To update the build information in updateBuildInfo with the location of the CBLAS header files, use the build informationaddIncludePaths method.

To add preprocessor macro definitions to the build information inupdateBuildInfo, use the build informationaddDefines method.

To specify the compiler options in updateBuildInfo, use the build information addCompileFlags method.

To specify the linker options in updateBuildInfo, use the build information addLinkFlags method.

The getBLASDoubleComplexTypeName method returns the type used for double-precision complex variables in the generated code. If your BLAS library takes a type other than double* and void* for double-precision complex array arguments, include this method in your callback class definition.

function doubleComplexTypeName = getBLASDoubleComplexTypeName() doubleComplexTypeName = 'my_double_complex_type'; end

Replace my_double_complex_type with the type that your BLAS library takes for double-precision complex array arguments.

The getBLASSingleComplexTypeName method returns the type used for single-precision complex variables in the generated code. If your BLAS library takes a type other than float* and void* for single-precision complex array arguments, include this method in your callback class definition.

function singleComplexTypeName = getBLASSingleComplexTypeName() doubleComplexTypeName = 'my_single_complex_type'; end

Replace my_single_complex_type with the type that your BLAS library takes for single-precision complex array arguments.

The useEnumNameRatherThanTypedef method returnsfalse by default. If types for enumerations in your BLAS library include the enum keyword, redefine this method to returntrue in your callback class definition.

function p = useEnumNameRatherThanTypedef() p = true; end

Callback Class for OpenBLAS

This example is an implementation of the BLAS callback classopenblascallback for linking to the OpenBLAS library on a Linux® platform. openblascallback does not have explicit implementations of getBLASDoubleComplexTypeName,getBLASSingleComplexTypeName, anduseEnumNameRatherThanTypedef. It inherits these methods fromcoder.BLASCallback.

classdef openblascallback < coder.BLASCallback methods (Static) function updateBuildInfo(buildInfo, buildctx) libPriority = ''; libPreCompiled = true; libLinkOnly = true; libName = 'libopenblas.a';
libPath = fullfile(pwd,'openblas'); incPath = fullfile(pwd,'openblas'); buildInfo.addLinkFlags('-lpthread'); buildInfo.addLinkObjects(libName, libPath, ... libPriority, libPreCompiled, libLinkOnly); buildInfo.addIncludePaths(incPath); end function headerName = getHeaderFilename() headerName = 'cblas.h'; end function intTypeName = getBLASIntTypeName() intTypeName = 'blasint'; end end end

If you generate C++ code that includes calls to OpenBLAS library functions, compiling it with the -pedantic option produces warnings. To disable the -pedantic compiler option, in theupdateBuildInfo method, include these lines:

if buildctx.getTargetLang() == 'C++' buildInfo.addCompileFlags('-Wno-pedantic'); end

OpenBLAS does not support the C89/C90 standard.

Version History

Introduced in R2018b