Main Content

coder.HardwareImplementation

Hardware-specific configuration parameters for C/C++ code generation from MATLAB 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 to codegen. To create a coder.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:

By default, the coder.HardwareImplementation properties specify characteristics of the MATLAB® host computer. To specify a different device, modify the ProdHWDeviceType 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 (a coder.CodeConfig object or a coder.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 the coder.HardwareImplementation object.

Properties

expand all

Description of coder.HardwareImplementation object, specified as a character vector.

Object name, specified as a character vector.

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 to true and work only with the production properties.

Setting ProdEqTarget to false is an advanced feature that enables the target hardware properties. If you change ProdEqTarget 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 to false for testing, before you deploy the generated code to the production hardware, set ProdEqTarget to true 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 is true, the software checks the production properties (properties that start with Prod). If ProdEqTarget is false, the software checks the target properties (properties that start with Target). See Code Verification Through Software-in-the-Loop and Processor-in-the-Loop Execution (Embedded Coder).

Production Hardware Properties

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.

This property is read-only.

Length in bits of the C double data type that the production hardware supports.

This property is read-only.

Length in bits of the C floating-point data type that the production hardware supports.

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.

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.

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 the ProdBitPerLongLong property.

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.

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 of ProdBitPerInt.

Length in bits of the C short data type that the production hardware supports, specified as a multiple of 8, from 8 through 32.

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 of ProdBitPerInt.

Significance of the first byte of a data word for the production hardware, specified as one of the values in this table.

ValueDescription
'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.

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.

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.

ValueDescription
'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.

C compiler support for the long long data type, specified as one of the values in this table.

ValueDescription
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 C long 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 C long long data type.

  • If your compiler does not support C long long, do not select this parameter.

Dependency:

  • ProdLongLongMode enables use of the ProdBitPerLongLong property.

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.

ValueDescription
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.

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

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.

This property is read-only.

Length in bits of the C double data type that the target hardware supports.

This property is read-only.

Length in bits of the C floating-point data type that the target hardware supports.

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.

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.

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 the TargetBitPerLongLong property.

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.

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.

Length in bits of the C short data type that the target hardware supports, specified as a multiple of 8, from 8 through 32.

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 of ProdBitPerInt.

Significance of the first byte of a data word for the target hardware, specified as one of the values in this table.

ValueDescription
'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.

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

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.

ValueDescription
'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.

C compiler support for the long long data type, specified as one of the values in this table.

ValueDescription
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 C long 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 C long long data type.

  • If your compiler does not support C long long, do not select this parameter.

Dependency:

  • TargetLongLongMode enables use of the TargetBitPerLongLong property.

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.

ValueDescription
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.

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

collapse all

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 the HardwareImplementation 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 the coder.HardwareImplementation object.

codegen -config cfg myFunction

Open the dialog box for the configuration object that refers to the coder.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 to None - select device below. Then, set the Device 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.

Tips

To set the ProdHWDeviceType property, select the device from the available options by opening a dialog box for the configuration object that refers to the coder.HardwareImplementation object. See Access Hardware Implementation Properties with a Dialog Box.

Alternative Functionality

  • You can directly create a coder.HardwareImplementation object and assign it to a coder.CodeConfig object or a coder.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 a coder.EmbeddedCodeConfig object to a coder.Hardware object. To create a coder.Hardware object, use coder.hardware. For example:

    cfg = coder.config('lib');
    hw = coder.hardware('Raspberry Pi');
    cfg.Hardware = hw;

Version History

Introduced in R2011a