Skip to main content

cudaDevSmResourceSplit

Function cudaDevSmResourceSplit 

Source
pub unsafe extern "C" fn cudaDevSmResourceSplit(
    result: *mut cudaDevResource,
    nbGroups: c_uint,
    input: *const cudaDevResource,
    remainder: *mut cudaDevResource,
    flags: c_uint,
    groupParams: *mut cudaDevSmResourceGroupParams,
) -> cudaError_t
Expand description

Splits a cudaDevResourceType::cudaDevResourceTypeSm resource into structured groups.

This API will split a resource of cudaDevResourceType::cudaDevResourceTypeSm into nbGroups structured device resource groups (the result array), as well as an optional remainder, according to a set of requirements specified in the groupParams array. The term “structured” is a trait that specifies the result has SMs that are co-scheduled together. This co-scheduling can be specified via the coscheduledSmCount field of the groupParams structure, while the smCount will specify how many SMs are required in total for that result. The remainder is always “unstructured”, it does not have any set guarantees with respect to co-scheduling and those properties will need to either be queried via the occupancy set of APIs or further split into structured groups by this API.

The API has a discovery mode for use cases where it is difficult to know ahead of time what the SM count should be. Discovery happens when the smCount field of a given groupParams array entry is set to 0 - the smCount will be filled in by the API with the derived SM count according to the provided groupParams fields and constraints. Discovery can be used with both a valid result array and with a NULL result pointer value. The latter is useful in situations where the smCount will end up being zero, which is an invalid value to create a result entry with, but allowed for discovery purposes when the result is NULL.

The groupParams array is evaluated from index 0 to nbGroups - 1. For each index in the groupParams array, the API will evaluate which SMs may be a good fit based on constraints and assign those SMs to result. This evaluation order is important to consider when using discovery mode, as it helps discover the remaining SMs.

For a valid call:

  • result should point to a cudaDevResource array of size nbGroups, or alternatively, may be NULL, if the developer wishes for only the groupParams entries to be updated

  • input should be a valid cudaDevResourceType::cudaDevResourceTypeSm resource that originates from querying the execution context, or device.

  • The remainder group may be NULL.

  • There are no API flags at this time, so the value passed in should be 0.

  • A cudaDevSmResourceGroupParams array of size nbGroups. Each entry must be zero-initialized.

    • smCount: must be either 0 or in the range of [2,inputSmCount] where inputSmCount is the amount of SMs the input resource has. smCount must be a multiple of 2, as well as a multiple of coscheduledSmCount. When assigning SMs to a group (and if results are expected by having the result parameter set), smCount cannot end up with 0 or a value less than coscheduledSmCount otherwise cudaError_t::CUDA_ERROR_INVALID_RESOURCE_CONFIGURATION will be returned.
    • coscheduledSmCount: allows grouping SMs together in order to be able to launch clusters on Compute Architecture 9.0+. The default value may be queried from the device’s cudaDevResourceType::cudaDevResourceTypeSm resource (8 on Compute Architecture 9.0+ and 2 otherwise). The maximum is 32 on Compute Architecture 9.0+ and 2 otherwise.
    • preferredCoscheduledSmCount: Attempts to merge coscheduledSmCount groups into larger groups, in order to make use of preferredClusterDimensions on Compute Architecture 10.0+. The default value is set to coscheduledSmCount.
    • flags:
  • cudaDevSmResourceGroupBackfill: Treats constraints as a hint, ignoring them if necessary to reach the requested smCount. Lets smCount be a non-multiple of coscheduledSmCount, filling the difference between SM count and already assigned co-scheduled groupings with other SMs. This lets any resulting group behave similar to the remainder group for example. When used with cudaDevSmResourceGroupLocalityDomainId, backfill fills up to the requested smCount using the target locality domain first, then SMs not attributed to any locality domain, then SMs from other locality domains. If no SMs can be found in the requested locality domain, cudaError_t::CUDA_ERROR_INVALID_RESOURCE_CONFIGURATION is returned.

Example params and their effect:

A groupParams array element is defined in the following order:

{ .smCount, .coscheduledSmCount, .preferredCoscheduledSmCount, .flags, \/\* .reserved \*\/ }
// Example 1
// Will discover how many SMs there are, that are co-scheduled in groups of smCoscheduledAlignment.
// The rest is placed in the optional remainder.
cudaDevSmResourceGroupParams params { 0, 0, 0, 0 };
// Example 2
// Assuming the device has 10+ SMs, the result will have 10 SMs that are co-scheduled in groups of 2 SMs.
// The rest is placed in the optional remainder.
cudaDevSmResourceGroupParams params { 10, 2, 0, 0};
// Setting the coscheduledSmCount to 2 guarantees that we can always have a valid result
// as long as the SM count is less than or equal to the input resource SM count.
// Example 3
// A single piece is split-off, but instead of assigning the rest to the remainder, a second group contains everything else
// This assumes the device has 10+ SMs (8 of which are coscheduled in groups of 4),
// otherwise the second group could end up with 0 SMs, which is not allowed.
cudaDevSmResourceGroupParams params { {8, 4, 0, 0}, {0, 2, 0, cudaDevSmResourceGroupBackfill } }

The difference between a catch-all param group as the last entry and the remainder is in two aspects:

  • The remainder may be NULL / _TYPE_INVALID (if there are no SMs remaining), while a result group must always be valid.
  • The remainder does not have a structure, while the result group will always need to adhere to a structure of coscheduledSmCount (even if its just 2), and therefore must always have enough coscheduled SMs to cover that requirement (even with the cudaDevSmResourceGroupBackfill flag enabled).

Splitting an input into N groups, can be accomplished by repeatedly splitting off 1 group and re-splitting the remainder (a bisect operation). However, it’s recommended to accomplish this with a single call wherever possible.

Note that as specified by cudaStreamAddCallback no CUDA function may be called from callback. cudaError_t::CUDA_ERROR_NOT_PERMITTED may, but is not guaranteed to, be returned as a diagnostic in such case.

§Parameters

  • result: Output array of cudaDevResource resources. Can be NULL, alongside an smCount of 0, for discovery purpose.
  • nbGroups: Specifies the number of groups in result and groupParams.
  • input: Input SM resource to be split. Must be a valid cudaDevResourceType::cudaDevResourceTypeSm resource.
  • remainder: If splitting the input resource leaves any SMs, the remainder is placed in here.
  • flags: Flags specifying how the API should behave. The value should be 0 for now.
  • groupParams: Description of how the SMs should be split and assigned to the corresponding result entry.

§Return value

See also: cuDevSmResourceSplit, cudaDeviceGetDevResource, cudaExecutionCtxGetDevResource, cudaDevResourceGenerateDesc.