gpt4 book ai didi

cuda - cublasSetVector() 与 cudaMemcpy()

转载 作者:行者123 更新时间:2023-12-04 12:20:58 28 4
gpt4 key购买 nike

我想知道是否有区别:

// cumalloc.c - Create a device on the device
HOST float * cudamath_vector(const float * h_vector, const int m)
{
float *d_vector = NULL;
cudaError_t cudaStatus;
cublasStatus_t cublasStatus;

cudaStatus = cudaMalloc(&d_vector, sizeof(float) * m );

if(cudaStatus == cudaErrorMemoryAllocation) {
printf("ERROR: cumalloc.cu, cudamath_vector() : cudaErrorMemoryAllocation");
return NULL;
}


/* THIS: */ cublasSetVector(m, sizeof(*d_vector), h_vector, 1, d_vector, 1);

/* OR THAT: */ cudaMemcpy(d_vector, h_vector, sizeof(float) * m, cudaMemcpyHostToDevice);


return d_vector;
}
cublasSetVector()有两个参数 incxincydocumentation says :

The storage spacing between consecutive elements is given by incx for the source vector x and for the destination vector y.



NVIDIA forum有人说:

iona_me: "incx and incy are strides measured in floats."



那么这是否意味着对于 incx = incy = 1 float[] 的所有元素将是 sizeof(float) -对齐并为 incx = incy = 2会有一个 sizeof(float) - 每个元素之间的填充?
  • 除了这两个参数和 cublasHandle - 做cublasSetVector()还有什么cudaMalloc()不行吗?
  • 传递 的向量/矩阵是否会保存?不是 用他们各自的 cublas*() 创建函数到其他 CUBLAS 函数来操作它们?
  • 最佳答案

    Massimiliano Fatica 提供的 thread of the NVIDIA Forum 中有一条评论,证实了我在上述评论中的陈述(或者,更好地说,我的评论源于对阅读我链接到的帖子的记忆)。尤其

    cublasSetVector, cubblasGetVector, cublasSetMatrix, cublasGetMatrix are thin wrappers around cudaMemcpy and cudaMemcpy2D. Therefore, no significant performance differences are expected between the two sets of copy functions.



    因此,您可以安全地将 cudaMalloc 创建的任何数组作为输入传递给 cublasSetVector

    关于步伐,指南中可能有打印错误(从 CUDA 6.0 开始),它说

    The storage spacing between consecutive elements is given by incx for the source vector x and for the destination vector y.



    也许 应该读作

    The storage spacing between consecutive elements is given by incx for the source vector x and incy for the destination vector y.

    关于cuda - cublasSetVector() 与 cudaMemcpy(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24121143/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com