Ошибка CUDA 101 с позиционированием cudaMemPrefetchAsync на WSL2C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Ошибка CUDA 101 с позиционированием cudaMemPrefetchAsync на WSL2

Сообщение Anonymous »

Я запускаю эти фрагменты на WSL с использованием CUDA 12.1.
snip1 возвращает ошибку CUDA 101: неверный порядковый номер устройства, а snip2 работает без проблем.
Разница между этими фрагментами заключается только в позициях cudaMemPrefetchAsync вызывает.
Эта разница обусловлена ​​исключительно положением cudaMemPrefetchAsync? Каков механизм такого поведения?
// snip1
#include

#include

void checkError()
{
cudaError_t err_;
err_ = cudaGetLastError();
if (err_ != cudaSuccess)
{
std::printf("CUDA error %d:%s at %s:%d\n", err_, cudaGetErrorString(err_), __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
}

__global__ void init_curand(curandState *states, unsigned long long seed)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
int idx = i * blockDim.y * gridDim.y + j;
curand_init(seed, idx, 0, &states[idx]);
}

int main()
{
int deviceId;
int numberOfSMs;

cudaGetDevice(&deviceId);
cudaDeviceGetAttribute(&numberOfSMs, cudaDevAttrMultiProcessorCount, deviceId);
printf("Device ID: %d\tNumber of SMs: %d\n", deviceId, numberOfSMs);

dim3 threadsPerBlock(16, 16);
dim3 numBlocks(8 * numberOfSMs, 8 * numberOfSMs);

const int M = 10;
const int N = 20;
const int bytes = M * N * sizeof(int8_t);
int8_t *noisy;
int8_t *ising1;
int8_t *ising2;
cudaMallocManaged(&noisy, bytes);
cudaMallocManaged(&ising1, bytes);
cudaMallocManaged(&ising2, bytes);
curandState *states;
cudaMalloc(&states, numBlocks.x * threadsPerBlock.x * numBlocks.y * threadsPerBlock.y *
sizeof(curandState));

/* ??? */
cudaMemPrefetchAsync(noisy, bytes, deviceId);
cudaMemPrefetchAsync(ising1, bytes, deviceId);
cudaMemPrefetchAsync(ising2, bytes, deviceId);

init_curand(states, time(NULL));
checkError();

return 0;
}

// snip2
#include

#include

void checkError()
{
cudaError_t err_;
err_ = cudaGetLastError();
if (err_ != cudaSuccess)
{
std::printf("CUDA error %d:%s at %s:%d\n", err_, cudaGetErrorString(err_), __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
}

__global__ void init_curand(curandState *states, unsigned long long seed)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
int idx = i * blockDim.y * gridDim.y + j;
curand_init(seed, idx, 0, &states[idx]);
}

int main()
{
int deviceId;
int numberOfSMs;

cudaGetDevice(&deviceId);
cudaDeviceGetAttribute(&numberOfSMs, cudaDevAttrMultiProcessorCount, deviceId);
printf("Device ID: %d\tNumber of SMs: %d\n", deviceId, numberOfSMs);

dim3 threadsPerBlock(16, 16);
dim3 numBlocks(8 * numberOfSMs, 8 * numberOfSMs);

const int M = 10;
const int N = 20;
const int bytes = M * N * sizeof(int8_t);
int8_t *noisy;
int8_t *ising1;
int8_t *ising2;
cudaMallocManaged(&noisy, bytes);
cudaMallocManaged(&ising1, bytes);
cudaMallocManaged(&ising2, bytes);

curandState *states;
cudaMalloc(&states, numBlocks.x * threadsPerBlock.x * numBlocks.y * threadsPerBlock.y *
sizeof(curandState));

init_curand(states, time(NULL));
checkError();

/* ??? */
cudaMemPrefetchAsync(noisy, bytes, deviceId);
cudaMemPrefetchAsync(ising1, bytes, deviceId);
cudaMemPrefetchAsync(ising2, bytes, deviceId);

return 0;
}


Подробнее здесь: https://stackoverflow.com/questions/785 ... ng-on-wsl2
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»