0

考虑下面的程序。

它获取 CUDA 设备当前的共享内存银行大小配置;将其设置为另一个值;然后再次得到它。不幸的是,这是输出:

The reported shared memory bank size for device 0 is: 4 bytes.
Will now set the shared memory bank size for device 0 to: 8 bytes.
After setting shared memory bank size to 8 bytes,
the reported shared memory bank size for device 0 is: 4 bytes.

我的问题:为什么会发生这种情况?具体来说,

  • 某些 CUDA GPU 会忽略此设置吗?如果是这样,为什么设置银行配置时没有返回错误?
  • 我的程序可能只是有一个错误吗?
  • 是因为我同时使用运行时 API 和驱动程序 API 调用吗?

笔记:

  • 为了便于阅读,我已经删除了大部分错误检查,但您需要相信我,我确实会检查错误。
  • 我在 Devuan GNU/Linux Chimaera 上的 GTX 1050 Ti Boost、CUDA 11.4、驱动程序 470.57.02 上运行它。
#include <cuda.h>
#include <cuda_runtime.h>

#include <iostream>
#include <cassert>

const char* bank_size_descriptions[] = {"default", "4 bytes", "8 bytes" };
const char* bank_size_description(CUsharedconfig config) { return bank_size_descriptions[config]; }


int main()
{
    int device_id { 0 };
    CUcontext top_of_context_stack;
    CUsharedconfig bs_config;
    CUcontext primary_context_handle;
    CUresult status;

    cudaSetDevice(0);
    cuDevicePrimaryCtxRetain(&primary_context_handle, device_id);
    cuCtxGetCurrent(&top_of_context_stack);
    assert(top_of_context_stack == primary_context_handle);
    cuCtxGetSharedMemConfig(&bs_config);

    std::cout
        << "The reported shared memory bank size for device "
        << device_id << " is: " << bank_size_description(bs_config) << ".\n";
    auto new_bs_config =
        (bs_config == CU_SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE) ?
        CU_SHARED_MEM_CONFIG_EIGHT_BYTE_BANK_SIZE :
        CU_SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE;
    std::cout
        << "Will now set the shared memory bank size for device "
        << device_id << " to: " << bank_size_description(new_bs_config) << ".\n";

    status = cuCtxSetSharedMemConfig(new_bs_config);
    assert(status == CUDA_SUCCESS);

    cuCtxGetSharedMemConfig(&bs_config);

    if (bs_config != new_bs_config) {
        std::cerr
            << "After setting shared memory bank size to " << bank_size_description(new_bs_config)
            << ",\nthe reported shared memory bank size for device "
            << device_id << " is: " << bank_size_description(bs_config) << '.' << std::endl;
        exit(EXIT_FAILURE);
    }
}
4

1 回答 1

3

CUDA 驱动程序 api 文档说明如下。

This function will do nothing on devices with fixed shared memory bank size.

我认为在这种情况下“什么都不做”是成功的,因此不会返回错误代码。

于 2021-11-22T12:41:00.353 回答