coder.HardwareImplementation - Hardware-specific configuration parameters for C/C++ code generation from
MATLAB code - MATLAB ([original](https://www.mathworks.com/help/coder/ref/coder.hardwareimplementation.html)) ([raw](?raw))
Hardware-specific configuration parameters for C/C++ code generation fromMATLAB code
Description
A coder.HardwareImplementation
object contains hardware-specific configuration parameters that codegen
uses for generating a static library, a dynamically linked library, or an executable program.
To use a coder.HardwareImplementation
object, you must associate it with a configuration object (a coder.CodeConfig object or a coder.EmbeddedCodeConfig object) that you pass tocodegen
. To create acoder.HardwareImplementation
object and associate it with a configuration object, create the configuration object by using coder.config.
Access coder.HardwareImplementation
properties in one of these ways:
- The
HardwareImplementation
property of the associated configuration object. For example:
cfg = coder.config('lib');
cfg.HardwareImplementation.ProdHWDeviceType - A dialog box for the associated configuration object. See Access Hardware Implementation Properties with a Dialog Box.
By default, the coder.HardwareImplementation
properties specify characteristics of the MATLAB® host computer. To specify a different device, modify theProdHWDeviceType
property. The hardware device determines the values of the other device-specific properties and the properties that you can change.
Creation
To create a coder.HardwareImplementation
object, use coder.config to create a configuration object (acoder.CodeConfig
object or acoder.EmbeddedCodeConfig
object) for generation of standalone code. When coder.config
creates the configuration object, it also creates a coder.HardwareImplementation
object.coder.config
sets the HardwareImplementation
property of the configuration object to thecoder.HardwareImplementation
object.
Properties
Description
— Object description
'class HardwareImplementation: Hardware implementation specifications.'
(default) | character vector
Description of coder.HardwareImplementation
object, specified as a character vector.
Name
— Object name
'HardwareImplementation'
(default) | character vector
Object name, specified as a character vector.
ProdEqTarget
— Equivalence of production and target hardware characteristics
true
(default) | false
Equivalence of production and target (test) hardware characteristics, specified as true
or false
.
A coder.HardwareImplementation
object has two sets of hardware properties—one for the characteristics of the production hardware and one for the characteristics of the target (test) hardware. By default, codegen
uses the properties of the production hardware. Typically, you leave ProdEqTarget
set totrue
and work only with the production properties.
Setting ProdEqTarget
to false
is an advanced feature that enables the target hardware properties. If you changeProdEqTarget
to false
,codegen
uses the properties for the target hardware and generates code to emulate the behavior of the production hardware on the target hardware. If you set ProdEqTarget
tofalse
for testing, before you deploy the generated code to the production hardware, set ProdEqTarget
totrue
and regenerate the code.
At the beginning of an Embedded Coder® processor-in-the-loop (PIL) execution, the software checks the hardware implementation properties with reference to the target hardware on which the PIL execution runs. If ProdEqTarget
istrue
, the software checks the production properties (properties that start with Prod
). IfProdEqTarget
is false
, the software checks the target properties (properties that start withTarget
). See Code Verification Through Software-in-the-Loop and Processor-in-the-Loop Execution (Embedded Coder).
Production Hardware Properties
ProdBitPerChar
— Length in bits of the C char
data type
8 (default) | multiple of 8, from 8 through 32
Length in bits of the C char data type that the production hardware supports, specified as an integer value from 8 through 32. The value must be a multiple of 8.
ProdBitPerDouble
— Length in bits of the C double
data type
64
This property is read-only.
Length in bits of the C double data type that the production hardware supports.
ProdBitPerFloat
— Length in bits of the C floating-point data type
32
This property is read-only.
Length in bits of the C floating-point data type that the production hardware supports.
ProdBitPerInt
— Length in bits of the C int
data type
32 (default) | multiple of 8, from 8 through 32
Length in bits of the C int
data type that the production hardware supports, specified as an integer value from 8 through 32. The value must be a multiple of 8.
ProdBitPerLong
— Length in bits of the C long
data type
32 (default) | multiple of 8, from 32 through 128
Length in bits of the C long
data type that the production hardware supports, specified as an integer value from 32 through 128. The value must be a multiple of 8.
ProdBitPerLongLong
— Length in bits of the C long long
data type
64 (default) | multiple of 8, from 64 through 128
Length in bits of the C long long
data type that the production hardware supports, specified as an integer value from 64 through 128. The value must be a multiple of 8.
Use the C long long
data type only if your C compiler supports long long
.
Dependency:
ProdLongLongMode
enables use of theProdBitPerLongLong
property.
ProdBitPerPointer
— Length in bits of pointer data
64 (default) | multiple of 8, from 8 through 64
Length in bits of pointer data that the production hardware supports, specified as an integer value from 8 through 64. The value must be a multiple of 8.
ProdBitPerPtrDiffT
— Length in bits of ptrdiff_t
data
64 (default) | 8 | 16 | 24 | 32 | 40 | 64 | 128
Length in bits of ptrdiff_t
data that the production hardware supports, specified as 8, 16, 24, 32, 40, 64, or 128. The value must be greater than or equal to the value ofProdBitPerInt
.
ProdBitPerShort
— Length in bits of the C short
data type
16 (default) | multiple of 8, from 8 through 32
Length in bits of the C short
data type that the production hardware supports, specified as a multiple of 8, from 8 through 32.
ProdBitPerSizeT
— Length in bits of size_t
data
64 (default) | 8 | 16 | 24 | 32 | 40 | 64 | 128
Length in bits of size_t
data that the production hardware supports, specified as 8, 16, 24, 32, 40, 64, or 128. The value must be greater than or equal to the value ofProdBitPerInt
.
ProdEndianess
— Significance of the first byte of a data word
'LittleEndian'
(default) | 'BigEndian'
| 'Unspecified'
Significance of the first byte of a data word for the production hardware, specified as one of the values in this table.
Value | Description |
---|---|
'LittleEndian' | This value is the default value. The least significant byte appears first in the byte ordering. |
'BigEndian' | The most significant byte appears first in the byte ordering. |
'Unspecified' | The code determines the endianness of the hardware. This value produces less efficient code. |
ProdHWDeviceType
— Manufacturer and type of the production hardware board
'Generic->MATLAB Host Computer'
(default) | character vector
Manufacturer and type of the production hardware board, specified as a character vector.
Specifying the ProdHWDeviceType
property sets device-specific properties for the production hardware. You can modify a device-specific property only if it is enabled for the specified hardware.
codegen
cannot generate code for ASICs or FPGAs. If you set ProdHWDeviceType
to'ASIC/FPGA->ASIC/FPGA'
,ProdEqTarget
becomes false
so that the code generator uses the properties for the target(test) device.'ASIC/FPGA->ASIC/FPGA'
is not a valid value for TargetHWDeviceType
.
ProdIntDivRoundTo
— Rounding for division of two signed integers
'Zero'
(default) | 'Undefined'
| 'Floor'
Rounding by the compiler for the production hardware of the result of division of two signed integers, specified as one of the values in this table.
Value | Description |
---|---|
'Zero' | This value is the default value. If the quotient is between two integers, the compiler rounds to the integer that is closer to zero. |
'Floor' | If the quotient is between two integers, the compiler rounds to the integer that is closer to negative infinity. |
'Undefined' | The compiler does not round toward zero or negative infinity, or the compiler rounding behavior is undefined. |
ProdLongLongMode
— Long long data type support
true
(default) | false
C compiler support for the long long
data type, specified as one of the values in this table.
Value | Description |
---|---|
true | This value is the default value.The code generator uses the Clong long data type in the generated code. |
false | The code generator does not use the Clong long data type in the generated code. |
Most C99 compilers support long long
.
Tips:
ProdLongLongMode
is enabled only if the specified production hardware supports the Clong long
data type.- If your compiler does not support C
long long
, do not select this parameter.
Dependency:
ProdLongLongMode
enables use of theProdBitPerLongLong
property.
ProdShiftRightIntArith
— Implementation of signed integer right shift as arithmetic right shift
true (default) | false
Implementation by the C compiler for the production hardware of a signed integer right shift as an arithmetic right shift, specified as one of the values in this table.
Value | Description |
---|---|
true | This value is the default value. Indicates that the C compiler implements a right shift of a signed integer as an arithmetic right shift. An arithmetic right shift fills the bit vacated by the right shift with the value of the most significant bit. The most significant bit indicates the sign of the number. |
false | Indicates that the C compiler does not implement a right shift of a signed integer as an arithmetic right shift. |
ProdWordSize
— Microprocessor native word size
64 (default) | multiple of 8, from 8 through 64
Microprocessor native word size for the production hardware, specified as an integer value from 8 through 64. The value must be a multiple of 8.
Target Hardware Properties
TargetBitPerChar
— Length in bits of the C char
data type
8 (default) | multiple of 8, from 8 through 32
Length in bits of the C char data type that the target hardware supports, specified as an integer value from 8 through 32. The value must be a multiple of 8.
TargetBitPerDouble
— Length in bits of the C double
data type
64
This property is read-only.
Length in bits of the C double data type that the target hardware supports.
TargetBitPerFloat
— Length in bits of the C floating-point data type
32
This property is read-only.
Length in bits of the C floating-point data type that the target hardware supports.
TargetBitPerInt
— Length in bits of the C int
data type
32 (default) | multiple of 8, from 8 through 32
Length in bits of the C int
data type that the target hardware supports, specified as an integer value from 8 through 32. The value must be a multiple of 8.
TargetBitPerLong
— Length in bits of the C long
data type
32 (default) | multiple of 8, from 32 through 128
Length in bits of the C long
data type that the target hardware supports, specified as an integer value from 32 through 128. The value must be a multiple of 8.
TargetBitPerLongLong
— Length in bits of the C long long
data type
64 (default) | multiple of 8, from 64 through 128
Length in bits of the C long long
data type that the target hardware supports, specified as an integer value from 64 through 128. The value must be a multiple of 8.
Use the C long long
data type only if your C compiler supports long long
.
Dependency:
TargetLongLongMode
enables use of theTargetBitPerLongLong
property.
TargetBitPerPointer
— Length in bits of pointer data
64 (default) | multiple of 8, from 8 through 64
Length in bits of pointer data that the target hardware supports, specified as an integer value from 8 through 64. The value must be a multiple of 8.
TargetBitPerPtrDiffT
— Length in bits of ptrdiff_t
data
64 (default) | 8 | 16 | 24 | 32 | 40 | 64 | 128
Length in bits of ptrdiff_t
data, specified as 8, 16, 24, 32, 40, 64, or 128. The value must be greater than or equal to the value of ProdBitPerInt
.
TargetBitPerShort
— Length in bits of the C short
data type
16 (default) | multiple of 8, from 8 through 32
Length in bits of the C short
data type that the target hardware supports, specified as a multiple of 8, from 8 through 32.
TargetBitPerSizeT
— Length in bits of size_t
data
64 (default) | 8 | 16 | 24 | 32 | 40 | 64 | 128
Length in bits of size_t
data that the target hardware supports, specified as 8, 16, 24, 32, 40, 64, or 128. The value must be greater than or equal to the value ofProdBitPerInt
.
TargetEndianess
— Significance of the first byte of a data word
'LittleEndian'
(default) | 'BigEndian'
| 'Unspecified'
Significance of the first byte of a data word for the target hardware, specified as one of the values in this table.
Value | Description |
---|---|
'LittleEndian' | This value is the default value. The least significant byte appears first in the byte ordering. |
'BigEndian' | The most significant byte appears first in the byte ordering. |
'Unspecified' | The code determines the endianness of the hardware. This value produces less efficient code. |
TargetHWDeviceType:
— Manufacturer and type of the target (test) hardware board
'Generic->MATLAB Host Computer'
(default) | character vector
Manufacturer and type of the target (test) hardware board, specified as a character vector.
Specifying the TargetHWDeviceType
property sets values for the device-specific properties for the target hardware. You can modify a device-specific property only if it is enabled for the specified hardware.
codegen
cannot generate code for ASICs or FPGAs. If you set ProdHWDeviceType
to'ASIC/FPGA->ASIC/FPGA'
,ProdEqTarget
becomes false
so that the code generator uses the properties for the target(test) device.'ASIC/FPGA->ASIC/FPGA'
is not a valid value for TargetHWDeviceType
TargetIntDivRoundTo
— Rounding for division of two signed integers
'Zero'
(default) | 'Undefined'
| 'Floor'
Rounding by the compiler for the test hardware of the result of division of two signed integers, specified as one of the values in this table.
Value | Description |
---|---|
'Zero' | This value is the default value. If the quotient is between two integers, the compiler rounds to the integer that is closer to zero. |
'Floor' | If the quotient is between two integers, the compiler rounds to the integer that is closer to negative infinity. |
'Undefined' | The compiler does not round toward zero or negative infinity, or the compiler rounding behavior is undefined. |
TargetLongLongMode
— Long long data type support
true
(default) | false
C compiler support for the long long data type, specified as one of the values in this table.
Value | Description |
---|---|
true | This value is the default value. The code generator uses the C long long data type in the generated code. |
false | The code generator does not use the Clong long data type in the generated code. |
When using GPU Coder™, the code generator always uses the C long long
data type in the generated code.
Most C99 compilers support long long
.
Tips:
TargetLongLongMode
is enabled only if the specified production hardware supports the Clong long
data type.- If your compiler does not support C
long long
, do not select this parameter.
Dependency:
TargetLongLongMode
enables use of theTargetBitPerLongLong
property.
TargetShiftRightIntArith
— Implementation of signed integer right shift as arithmetic right shift
true (default) | false
Implementation by the C compiler for the production hardware of a signed integer right shift as an arithmetic right shift, specified as one of the values in this table.
Value | Description |
---|---|
true | This value is the default value. Indicates that the C compiler implements a right shift of a signed integer as an arithmetic right shift. An arithmetic right shift fills the bit vacated by the right shift with the value of the most significant bit. The most significant bit indicates the sign of the number. |
false | Indicates that the C compiler does not implement a right shift of a signed integer as an arithmetic right shift. |
TargetWordSize
— Microprocessor native word size
64 (default) | multiple of 8, from 8 through 64
Microprocessor native word size for the production hardware, specified as an integer value from 8 through 64. The value must be a multiple of 8.
Examples
Specify Hardware-Specific Parameters for C Code Generation
Create a configuration object for generation of standalone code. For example, create a configuration object for generation of a static library.
cfg = coder.config('lib');
coder.config
sets theHardwareImplementation
property of the configuration object to a coder.HardwareImplementation
object with default parameter values for the MATLAB host computer.
To specify a different hardware device and customize the device-specific properties, set the ProdHWDeviceType property of the coder.HardwareImplementation
object to one of the available devices. For example:
cfg.HardwareImplementation.ProdHWDeviceType = 'AMD->Athlon 64'
To use the coder.HardwareImplementation
object for code generation, use the -config
option to specify the code generation configuration object associated with thecoder.HardwareImplementation
object.
codegen -config cfg myFunction
Access Hardware Implementation Properties with a Dialog Box
Open the dialog box for the configuration object that refers to thecoder.HardwareImplementation
object. For example:
cfg = coder.config('lib'); open('cfg');
In the dialog box, click the Hardware tab.
If you installed a support package for your hardware board (requires Embedded Coder), select the board from the options in Hardware Board. Otherwise, set Hardware Board toNone - select device below
. Then, set theDevice vendor and Device type.
The hardware implementation settings have values for the specified device. To see or modify these settings, click the Customize hardware implementation link. You can modify a setting only if it is enabled for the specified device.
See Specify Configuration Parameters in Command-Line Workflow Interactively.
Alternative Functionality
- You can directly create a
coder.HardwareImplementation
object and assign it to acoder.CodeConfig
object or acoder.EmbeddedCodeConfig
object.
hw_cfg = coder.HardwareImplementation;
hw_cfg.ProdHWDeviceType = 'AMD->Athlon 64';
cfg = coder.config('lib');
cfg.HardwareImplementation = hw_cfg; - If you install a support package for your hardware, you can customize hardware-specific code generation parameters by setting the
Hardware
property of acoder.EmbeddedCodeConfig
object to acoder.Hardware
object. To create acoder.Hardware
object, use coder.hardware. For example:
cfg = coder.config('lib');
hw = coder.hardware('Raspberry Pi');
cfg.Hardware = hw;
Version History
Introduced in R2011a