Однако, если я использую memcpy_async с детализацией thread_block`, я не могу заставить его работать.
Я основывал свой код на документации конвейера CUDA.
Вот мой MCVE:
Код: Выделить всё
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#ifdef __INTELLISENSE__
#define __CUDACC__
#endif
#include
//#include
#include
#include
#include
static constexpr auto consumer = cuda::pipeline_role::consumer;
static constexpr auto producer = cuda::pipeline_role::producer;
__global__ void test_memcpy(int gdata[32]) {
assert(blockDim.x == 64);
const auto group = cooperative_groups::this_thread_block();
__shared__ cuda::pipeline_shared_state PipelineState;
const auto warpid = threadIdx.x >= warpSize;
const auto laneid = threadIdx.x & 31;
//warp 0 = consumer, warp 1 = producer
const auto role = warpid ? producer : consumer;
auto pipeline_test = cuda::make_pipeline(group, &PipelineState, role);
__shared__ int sdata[32];
sdata[laneid] = 0;
//only copy every other element, skip the even ones.
//setting this to always 4 makes no difference.
const size_t size = threadIdx.x & 1 ? sizeof(int) : 0;
__syncthreads();
if (role == producer) {
pipeline_test.producer_acquire();
cuda::memcpy_async(group, &sdata[laneid], &gdata[laneid], size, pipeline_test);
pipeline_test.producer_commit();
} else {
assert(role == consumer);
pipeline_test.consumer_wait();
printf("tid: %i: sdata[%i] = %i\n", threadIdx.x, laneid, sdata[laneid]);
pipeline_test.consumer_release();
}
}
int main() {
int* gdata;
int buffer[32];
cudaMalloc(&gdata, sizeof(buffer));
for (auto i = 0; auto& d: buffer) { d = i++; }
cudaMemcpy(gdata, buffer, sizeof(buffer), cudaMemcpyHostToDevice);
test_memcpy(gdata);
cudaDeviceSynchronize();
}
Я использую CUDA 13 и Visual Studio 17.9.6 на GTX 3070 (также известном как Compute 86).
Обновление версии до последней версии VS не имеет никакого значения.
Что я делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/797 ... line-roles
Мобильная версия