# ModelConfig

```cpp
#include <qbruntime/type.h>

class mobilint::ModelConfig
```

Configures a core mode and core allocation of a model for NPU inference.

The [`ModelConfig`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/modelconfig/index.md>) class provides methods for setting a core mode and allocating cores for NPU inference. Supported core modes are single-core, multi-core, global4-core, and global8-core. Users can also specify which cores to allocate for the model. Additionally, the configuration offers an option to enforce the use of a specific NPU bundle.

> [!NOTE]
>
> Deprecated functions are included for backward compatibility, but it is recommended to use the newer core mode configuration methods.

## Member functions

| Member | Description |
| --- | --- |
| [`ModelConfig`](<#modelconfig>) ×2 | Default constructor. This default-constructed object is initially set to auto-core mode. |
| [`setAutoCoreMode`](<#setautocoremode>) | Sets the model to detect [CoreMode](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) automatically. |
| [`setSingleCoreMode`](<#setsinglecoremode>) ×2 | Sets the model to use single-core mode for inference with a specified number of local cores. |
| [`setMultiCoreMode`](<#setmulticoremode>) | Sets the model to use multi-core mode for batch inference. |
| [`setGlobal4CoreMode`](<#setglobal4coremode>) | Sets the model to use global4-core mode for inference with a specified set of NPU clusters. |
| [`setGlobal8CoreMode`](<#setglobal8coremode>) | Sets the model to use global8-core mode for inference. |
| [`getCoreMode`](<#getcoremode>) | Gets the core mode to be applied to the model. |
| [`getCoreAllocationPolicy`](<#getcoreallocationpolicy>) | Gets the core allocation policy to be applied to the model. |
| [`getNumCores`](<#getnumcores>) | Gets the number of cores to be allocated for the model. |
| [`forceSingleNPUBundle`](<#forcesinglenpubundle>) | Forces the use of a specific NPU bundle. |
| [`getForcedNPUBundleIndex`](<#getforcednpubundleindex>) | Retrieves the index of the forced NPU bundle. |
| [`getCoreIds`](<#getcoreids>) | Returns the list of NPU CoreIds to be used for model inference. |
| [`getClusters`](<#getclusters>) | Returns the list of clusters to be used for model inference. |
| [`setAsyncPipelineEnabled`](<#setasyncpipelineenabled>) | Enables or disables the asynchronous pipeline required for asynchronous inference. |
| [`getAsyncPipelineEnabled`](<#getasyncpipelineenabled>) | Returns whether the asynchronous pipeline is enabled in this configuration. |
| [`setActivationSlots`](<#setactivationslots>) | Sets activation buffer slots for multi-activation supported model. |
| [`getActivationSlots`](<#getactivationslots>) | Returns activation buffer slot count. |
| [`setGlobalCoreMode`](<#setglobalcoremode>) |  |

### ModelConfig

```cpp
ModelConfig()
```

Default constructor. This default-constructed object is initially set to auto-core mode.

```cpp
ModelConfig(int num_cores)
```

deprecated

### setAutoCoreMode

```cpp
bool setAutoCoreMode()
```

Sets the model to detect [CoreMode](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) automatically.

In auto-core mode, the model automatically detects a supported [CoreMode](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) while using all available NPU cores. The [CoreMode](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) of each bundle is detected independently, so bundles of different CoreModes may run on the same model.

> [!NOTE]
>
> If a bundle of the model supports more than one [CoreMode](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>), [`CoreMode::Auto`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) is not supported. Set the [CoreMode](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) explicitly for such a model.

> [!NOTE]
>
> activation buffer slots will be reset after `setAutoCoreMode` is called.

**Returns**

true if the mode was successfully set, false otherwise.

### setSingleCoreMode

```cpp
bool setSingleCoreMode(int num_cores)
```

Sets the model to use single-core mode for inference with a specified number of local cores.

In single-core mode, each local core executes model inference independently. The number of cores used is specified by the `num_cores` parameter, and the core allocation policy is set to [`CoreAllocationPolicy::Auto`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coreallocationpolicy>), meaning the model will be automatically allocated to available local cores when the model is launched to the NPU, specifically when the [`Model::launch`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/model/#launch>) function is called.

**Parameters**

- `num_cores` *\[in\]* — The number of local cores to use for inference.

**Returns**

true if the mode was successfully set, false otherwise.

```cpp
bool setSingleCoreMode(std::vector<CoreId> core_ids)
```

Sets the model to use single-core mode for inference with a specific set of NPU local cores.

In single-core mode, each local core executes model inference independently. The user can specify a vector of CoreIds to determine which cores to use for inference.

**Parameters**

- `core_ids` *\[in\]* — A vector of CoreIds to be used for model inference.

**Returns**

true if the mode was successfully set, false otherwise.

### setMultiCoreMode

```cpp
bool setMultiCoreMode(std::vector<Cluster> clusters={Cluster::Cluster0, Cluster::Cluster1})
```

Sets the model to use multi-core mode for batch inference.

In multi-core mode, on Aries NPU, the four local cores within a cluster work together to process batch inference tasks efficiently. This mode is optimized for batch processing.

> [!NOTE]
>
> By default, the configuration is set to use all clusters.

**Parameters**

- `clusters` *\[in\]* — A vector of clusters to be used for multi-core batch inference.

**Returns**

true if the mode was successfully set, false otherwise.

### setGlobal4CoreMode

```cpp
bool setGlobal4CoreMode(std::vector<Cluster> clusters={Cluster::Cluster0, Cluster::Cluster1})
```

Sets the model to use global4-core mode for inference with a specified set of NPU clusters.

For Aries NPU, there are two clusters, each consisting of four local cores. In global4-core mode, four local cores within the same cluster work together to execute the model inference.

> [!NOTE]
>
> By default, the configuration is set to use all clusters.

**Parameters**

- `clusters` *\[in\]* — A vector of clusters to be used for model inference.

**Returns**

true if the mode was successfully set, false otherwise.

### setGlobal8CoreMode

```cpp
bool setGlobal8CoreMode()
```

Sets the model to use global8-core mode for inference.

For Aries NPU, there are two clusters, each consisting of four local cores. In global8-core mode, all eight local cores across the two clusters work together to execute the model inference.

**Returns**

true if the mode was successfully set, false otherwise.

### getCoreMode

```cpp
CoreMode getCoreMode() const
```

Gets the core mode to be applied to the model.

This reflects the core mode that will be used when the model is created.

**Returns**

The [`CoreMode`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) to be applied to the model.

### getCoreAllocationPolicy

```cpp
CoreAllocationPolicy getCoreAllocationPolicy() const
```

Gets the core allocation policy to be applied to the model.

This reflects the core allocation policy that will be used when the model is created.

**Returns**

The [`CoreAllocationPolicy`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coreallocationpolicy>) to be applied to the model.

### getNumCores

```cpp
int getNumCores() const
```

Gets the number of cores to be allocated for the model.

This represents the number of cores that will be allocated for inference when the model is launched to the NPU.

**Returns**

The number of cores to be allocated for the model.

### forceSingleNPUBundle

```cpp
bool forceSingleNPUBundle(int npu_bundle_index)
```

Forces the use of a specific NPU bundle.

This function forces the selection of a specific NPU bundle. If a non-negative index is provided, the corresponding NPU bundle is selected and runs without CPU offloading. If -1 is provided, all NPU bundles are used with CPU offloading enabled.

**Parameters**

- `npu_bundle_index` *\[in\]* — The index of the NPU bundle to force. A non-negative integer selects a specific NPU bundle (runs without CPU offloading), or -1 to enable all NPU bundles with CPU offloading.

**Returns**

true if the index is valid and the NPU bundle is successfully set, false if the index is invalid (less than -1).

### getForcedNPUBundleIndex

```cpp
int getForcedNPUBundleIndex() const
```

Retrieves the index of the forced NPU bundle.

This function returns the index of the NPU bundle that has been forced using the `forceSingleNPUBundle` function. If no NPU bundle is forced, the returned value will be -1.

**Returns**

The index of the forced NPU bundle, or -1 if no bundle is forced.

### getCoreIds

```cpp
const std::vector<CoreId> & getCoreIds() const
```

Returns the list of NPU CoreIds to be used for model inference.

The returned list reflects only what was set on this [ModelConfig](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/modelconfig/index.md>). What it contains depends on the configured [CoreMode](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>):

- Single mode via [setSingleCoreMode(std::vector\<CoreId\>)](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/modelconfig/#setsinglecoremode>): the specified CoreIds.
- Single mode via [setSingleCoreMode(int num\_cores)](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/modelconfig/#setsinglecoremode>): empty. The actual cores are resolved from the target NPU when the model is created.
- Multi, Global4, Global8, and Auto modes: empty. Use [getClusters()](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/modelconfig/#getclusters>) for the cluster-based modes.

**Returns**

A constant reference to the vector of NPU CoreIds.

### getClusters

```cpp
const std::vector<Cluster> & getClusters() const
```

Returns the list of clusters to be used for model inference.

The returned list reflects only what was set on this [ModelConfig](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/modelconfig/index.md>). What it contains depends on the configured [CoreMode](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>):

- Multi mode via [setMultiCoreMode()](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/modelconfig/#setmulticoremode>) and Global4 mode via [setGlobal4CoreMode()](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/modelconfig/#setglobal4coremode>): the specified clusters (defaults to all clusters).
- Single, Global8, and Auto modes: empty.

**Returns**

A constant reference to the vector of NPU clusters.

### setAsyncPipelineEnabled

```cpp
void setAsyncPipelineEnabled(bool enable)
```

Enables or disables the asynchronous pipeline required for asynchronous inference.

Call this function with `enable` set to `true` if you intend to use [`Model::inferAsync`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/model/#inferasync>) or [`Model::inferAsyncCHW`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/model/#inferasyncchw>), as the asynchronous pipeline is necessary for their operation.

If you are only using synchronous inference, such as [`Model::infer`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/model/#infer>) or [`Model::inferCHW`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/model/#inferchw>), it is recommended to keep the asynchronous pipeline disabled to avoid unnecessary overhead.

**Parameters**

- `enable` *\[in\]* — Set to `true` to enable the asynchronous pipeline; set to `false` to disable it.

### getAsyncPipelineEnabled

```cpp
bool getAsyncPipelineEnabled() const
```

Returns whether the asynchronous pipeline is enabled in this configuration.

**Returns**

`true` if the asynchronous pipeline is enabled; `false` otherwise.

### setActivationSlots

```cpp
void setActivationSlots(int count)
```

Sets activation buffer slots for multi-activation supported model.

Call this function if you want to set the number of activation buffer slots manually.

If you do not call this function, the default number of activation buffer slots is set differently depending on the [CoreMode](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>).

- [`CoreMode::Single`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) : 2 \* (the number of target core ids)
- [`CoreMode::Multi`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) : 2 \* (the number of target clusters)
- [`CoreMode::Global4`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) : 2 \* (the number of target clusters)
- [`CoreMode::Global8`](<https://docs.mobilint.com/runtime/en/v1.4/api/cpp/#coremode>) : 2

> [!NOTE]
>
> This function has no effect on MXQ file in version earlier than MXQv7.

> [!NOTE]
>
> Currently, LLM model's activation slot is fixed to 1 and ignoring `count`.

**Parameters**

- `count` *\[in\]* — Multi activation counts. Must be \>= 1.

### getActivationSlots

```cpp
int getActivationSlots() const
```

Returns activation buffer slot count.

> [!NOTE]
>
> This function has no meaning on MXQ file in version earlier than MXQv7.

**Returns**

Activation buffer slot count.

### setGlobalCoreMode

```cpp
bool setGlobalCoreMode(std::vector<Cluster> clusters)
```

deprecated
