About green context in cuda13.2.1

I want to try the green context using cuda 13.2.1. but I find some apis can not find and can not compile. such as cudaDevResourceDescDestroy and cudaGreenCtxDestroy, is the two api have not included in cuda 13.2.1?

I want to do some experiments on the Blackwell GPU and I’m not sure if CUDA 13.2 is support green context

Can you state which operating system you used? Which compiler? Is it a compiler or linker error?

My os is win10 x64, this is a compile error:

error : identifier “cudaGreenCtxDestroy” is undefined.

By the way, the following code run errror: cuda error code is 915, the gpu this blackwell PRO 4000

int main() {
	// 1. 初始化并设置设备
	int deviceId = 0;
	CUDA_CHECK(cudaSetDevice(deviceId));

	cudaDeviceProp deviceProp = { 0 };
	cudaGetDeviceProperties(&deviceProp, deviceId);

	// 2. 获取设备的全部 SM 资源信息
	cudaDevResource fullResource;
	CUDA_CHECK(cudaDeviceGetDevResource(deviceId, &fullResource, cudaDevResourceTypeSm));

	unsigned int totalSMs = fullResource.sm.smCount;
	printf("Total SMs on device: %u, %s\n", totalSMs, deviceProp.name);
	if (totalSMs < 24) {
		fprintf(stderr, "Error: Device has only %u SMs, need at least 24.\n", totalSMs);
		return -1;
	}

	// 3. 拆分 SM 资源 (使用 SplitByCount)
	//    目标: 创建两个分区,分别包含 16 个和 8 个 SM
	unsigned int smCounts[] = { 16, 8 };
	const unsigned int numPartitions = 2;

	// 定义数组来存储拆分结果和剩余资源
	cudaDevResource partitions[numPartitions];
	cudaDevResource remainingResource; // <- 关键点入下

	for (unsigned int i = 0; i < numPartitions; ++i) {
		// 注意:这里才是真正的单次拆分,每次拆分都需要更新输入
		// 如果用 baseResource = fullResource 反复传入,逻辑是错的!
		cudaDevResource inputResource = (i == 0) ? fullResource : remainingResource;
		unsigned int nbGroups = 1; // 每次请求创建一个分区

		CUDA_CHECK(cudaDevSmResourceSplitByCount(
			&partitions[i], // 输出: 本次拆分到的分区资源
			&nbGroups,              // 输出: 实际创建的分区数,应为 1 (成功时)
			&inputResource,         // 输入: 用于拆分的源资源
			&remainingResource,     // 输出: 拆分后剩余的源资源
			0,                      // flags (保留为0)
			smCounts[i]             // 输入: 请求的 SM 数量,API 会自动处理对齐
		));
		printf("Partition %u requested %u SMs.\n", i, smCounts[i]);
	}

	// 5. 为每个分区创建资源描述符,然后分别创建Green Context
	cudaExecutionContext_t greenCtx[2] = { nullptr, nullptr };
	for (int i = 0; i < 2; ++i) {
		cudaDevResourceDesc_t resourceDesc = nullptr;
		CUDA_CHECK(cudaDevResourceGenerateDesc(&resourceDesc, &partitions[i], 1));
		CUDA_CHECK(cudaGreenCtxCreate(&greenCtx[i], resourceDesc, deviceId, 0));
		//		CUDA_CHECK(cudaDevResourceDescDestroy(resourceDesc));
		std::cout << "Green Context " << i << " created with " << partitions[i].sm.smCount << " SMs." << std::endl;
	}

	// 6. 在各自的Green Context上创建流
	cudaStream_t streams[2];
	for (int i = 0; i < 2; ++i) {
		CUDA_CHECK(cudaExecutionCtxStreamCreate(&streams[i], greenCtx[i], cudaStreamDefault, 0));
	}



	printf("Green Contexts created successfully.\n");

}

There is only cuGreenCtxDestroy, not cuda. That means only a driver API function.
I believe you cannot destroy green contexts without the driver API.

in cuda 13.2, it has cudaGreenCtxCreate but has no cudaGreenCtxDestroy function?

my green context is created by cudaGreenCtxCreate, so it can not destroyed by the driver api

The function to destroy green context is

__host__ cudaError_t CUDARTAPI cudaExecutionCtxDestroy(cudaExecutionContext_t ctx)

thank you.

Also, do I need to destroy resourceDesc in the following code snippet? If necessary, which function should be called.

// 5. 为每个分区创建资源描述符,然后分别创建Green Context
cudaExecutionContext_t greenCtx[2] = { nullptr, nullptr };
for (int i = 0; i < 2; ++i) {
	cudaDevResourceDesc_t resourceDesc = nullptr;
	CUDA_CHECK(cudaDevResourceGenerateDesc(&resourceDesc, &partitions[i], 1));
	CUDA_CHECK(cudaGreenCtxCreate(&greenCtx[i], resourceDesc, deviceId, 0));
//	CUDA_CHECK(cudaDevResourceDescDestroy(resourceDesc));
	std::cout << "Green Context " << i << " created with " << partitions[i].sm.smCount << " SMs." << std::endl;
}

I do not know. I have not used green context before.

If you cannot find this information in the programming guide 4.6. Green Contexts — CUDA Programming Guide or runtime API CUDA Runtime API :: CUDA Toolkit Documentation you could file a bug asking for clarification

CUDA_CHECK(cudaDevSmResourceSplitByCount(
&partitions[i], // 输出: 本次拆分到的分区资源
&nbGroups, // 输出: 实际创建的分区数,应为 1 (成功时)
&inputResource, // 输入: 用于拆分的源资源
&remainingResource, // 输出: 拆分后剩余的源资源
0, // flags (保留为0)
smCounts[i] // 输入: 请求的 SM 数量,API 会自动处理对齐
));

the function return 915,

/**
* This error indicates one or more resources are insufficient or non-applicable for
* the operation.
*/
cudaErrorInvalidResourceConfiguration = 915,

Is there anyone who can give some advice?

Thanks