pub unsafe extern "C" fn cuDevSmResourceSplit(
result: *mut CUdevResource,
nbGroups: c_uint,
input: *const CUdevResource,
remainder: *mut CUdevResource,
flags: c_uint,
groupParams: *mut CU_DEV_SM_RESOURCE_GROUP_PARAMS,
) -> CUresultExpand description
Splits a CUdevResourceType::CU_DEV_RESOURCE_TYPE_SM resource into structured groups.
This API will split a resource of CUdevResourceType::CU_DEV_RESOURCE_TYPE_SM 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:
-
resultshould point to aCUdevResourcearray of sizenbGroups, or alternatively, may be NULL, if the developer wishes for only the groupParams entries to be updated -
inputshould be a validCUdevResourceType::CU_DEV_RESOURCE_TYPE_SMresource that originates from querying the green context, device context, or device. -
The
remaindergroup may be NULL. -
There are no API
flagsat this time, so the value passed in should be 0. -
A
CU_DEV_SM_RESOURCE_GROUP_PARAMSarray of sizenbGroups. 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 theinputresource has.smCountmust be a multiple of 2, as well as a multiple ofcoscheduledSmCountif it is nonzero. When assigning SMs to a group (and if results are expected by having theresultparameter set),smCountcannot end up with 0 or a value less thancoscheduledSmCountotherwiseCUresult::CUDA_ERROR_INVALID_RESOURCE_CONFIGURATIONwill 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’sCUdevResourceType::CU_DEV_RESOURCE_TYPE_SMresource (8 on Compute Architecture 9.0+ and 2 otherwise). The maximum is 32 on Compute Architecture 9.0+ and 2 otherwise. AcoscheduledSmCountof 0 uses the default value internally while preserving 0 ingroupParams. Cluster occupancy will be derived from the resulting SM topology.preferredCoscheduledSmCount:Attempts to mergecoscheduledSmCountgroups into larger groups, in order to make use ofpreferredClusterDimensionson Compute Architecture 10.0+. The default value is set tocoscheduledSmCount.flags:
CU_DEV_SM_RESOURCE_GROUP_BACKFILL:Treats constraints as a hint, ignoring them if necessary to reach the requestedsmCount. LetssmCountbe a non-multiple ofcoscheduledSmCount, filling the difference between SM count and already assigned co-scheduled groupings with other SMs. This lets any resulting group behave similar to theremaindergroup for example. When used withCUdevSmResourceGroup_flags::CU_DEV_SM_RESOURCE_GROUP_LOCALITY_DOMAIN_ID, backfill fills up to the requestedsmCountusing 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,CUresult::CUDA_ERROR_INVALID_RESOURCE_CONFIGURATIONis returned.CU_DEV_SM_RESOURCE_GROUP_LOCALITY_DOMAIN_ID:Specifies that the SM partition should be localized to the specifiedlocalityDomainId.localityDomainId:Specifies the locality domain that the partitioned SMs must be located on. Only valid whenCUdevSmResourceGroup_flags::CU_DEV_SM_RESOURCE_GROUP_LOCALITY_DOMAIN_IDis set in flags.
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 are available without imposing a co-scheduled group-size constraint.
// The rest is placed in the optional remainder.
CU_DEV_SM_RESOURCE_GROUP_PARAMS params { 0, 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.
CU_DEV_SM_RESOURCE_GROUP_PARAMS params { 10, 2, 0, 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.
CU_DEV_SM_RESOURCE_GROUP_PARAMS params { {8, 4, 0, 0, 0}, {0, 2, 0, CU_DEV_SM_RESOURCE_GROUP_BACKFILL, 0 } }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
CUdevSmResourceGroup_flags::CU_DEV_SM_RESOURCE_GROUP_BACKFILLflag 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.
§Parameters
result: Output array ofCUdevResourceresources. Can be NULL, alongside an smCount of 0, for discovery purpose.nbGroups: Specifies the number of groups inresultandgroupParams.input: Input SM resource to be split. Must be a validCUdevResourceType::CU_DEV_RESOURCE_TYPE_SMresource.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
CUresult::CUDA_SUCCESSCUresult::CUDA_ERROR_DEINITIALIZEDCUresult::CUDA_ERROR_NOT_INITIALIZEDCUresult::CUDA_ERROR_INVALID_DEVICECUresult::CUDA_ERROR_INVALID_VALUECUresult::CUDA_ERROR_INVALID_RESOURCE_TYPECUresult::CUDA_ERROR_INVALID_RESOURCE_CONFIGURATION
See also: cuGreenCtxGetDevResource, cuCtxGetDevResource, cuDeviceGetDevResource.