Line 43 IS Cuda_check (cudamemcpybatchasync (...)) . Подпись и описание API взяты из официальной документации: https://docs.nvidia.com/cuda/cuda-runti ... 102b9f9f91. /> code: < /strong> < /p>
Код: Выделить всё
#include
#include
#include
// CUDA error checking macro
#define CUDA_CHECK(call) \
{\
const cudaError_t err = call; \
if (err != cudaSuccess) { \
fprintf(stderr, "CUDA error at %s:%d - %s\n", __FILE__, __LINE__, cudaGetErrorString(err)); \
exit(EXIT_FAILURE); \
} \
} \
int main() {
// --- Configuration ---
const int NUM_COPIES = 1000;
const size_t COPY_SIZE_BYTES = 1024;
// --- Allocate Host and Device Memory ---
// We need multiple host and device pointers for individual copies
std::vector h_src;
std::vector d_dst;
std::vector sizes(NUM_COPIES, COPY_SIZE_BYTES);
for (int i = 0; i < NUM_COPIES; ++i) {
void* ptr_h, *ptr_d;
CUDA_CHECK(cudaMallocHost(&ptr_h, COPY_SIZE_BYTES));
CUDA_CHECK(cudaMalloc (&ptr_d, COPY_SIZE_BYTES));
h_src.push_back(ptr_h);
d_dst.push_back(ptr_d);
}
std::vector attrs(1);
attrs[0].srcLocHint.type = cudaMemLocationTypeHost;
attrs[0].dstLocHint.type = cudaMemLocationTypeDevice;
attrs[0].srcAccessOrder = cudaMemcpySrcAccessOrderAny;
attrs[0].flags = 0;
std::vector attrsIdxs = {0};
size_t numAttrs = attrs.size();
size_t fail_idx=0; // Variable to store the index of the failed copy if any
CUDA_CHECK(cudaMemcpyBatchAsync(
d_dst.data(),
h_src.data(),
sizes.data(),
NUM_COPIES,
attrs.data(),
attrsIdxs.data(),
numAttrs,
&fail_idx,
0 // Default stream
));
if( fail_idx!=SIZE_MAX ) throw std::runtime_error("Failed MemcpyBatchAsync at fail_idx = " + std::to_string(fail_idx) + "\n");
// --- Cleanup ---
for (int i = 0; i < NUM_COPIES; ++i) {
CUDA_CHECK(cudaFreeHost(h_src[i]));
CUDA_CHECK(cudaFree(d_dst[i]));
}
return 0;
}
[*] gpu: nvidia geforce rtx 5090
[*] версия драйвера: 575.57.08
[*] 575.57.08 nvidia -smi ): 12.9
[*] Компиляция: /usr/local/cuda-12.9/bin/nvcc -arch = sm_90 btest.cu -o a.out
. /> < /ul>
также протестировано на RTX3090 и CUDA 12.8 с компиляцией для SM_86. Та же самая ошибка «неверная аргументация». < /P>
Что еще может вызвать ошибку «неверного аргумента» для cudamemcpybatchasync в этом сценарии? Есть ли какие -либо тонкие требования или необычные факторы окружающей среды, которые я мог бы отсутствовать?
Подробнее здесь: https://stackoverflow.com/questions/796 ... d-argument
Мобильная версия