【问题标题】:multiplication two floats variables on CUDA在 CUDA 上乘以两个浮点变量
【发布时间】:2012-10-30 22:53:36
【问题描述】:

我有一个非常有趣的问题,但我解决了 3 个小时,但我无法弄清楚发生了什么以及为什么它不起作用。我试过谷歌它,但没有结果。

我正在 CUDA 上编写程序。我有这段非常简单的代码:

__global__ void calcErrorOutputLayer_kernel(*arguments...*)
{

   int idx = blockIdx.x * blockDim.x + threadIdx.x;
   float gradient;
   float derivation;
   derivation = pow((2/(pow(euler, neuron_device[startIndex + idx].outputValue) +
                pow(euler, -neuron_device[startIndex + idx].outputValue))), 2);
   gradient = (backVector_device[idx] - neuron_device[startIndex + idx].outputValue);

   gradient = gradient * derivation;   //this line doesn't work   
   gradient = gradient * 2.0;          //this line works

好的,所以梯度计算正确,推导也正确。但是当上线时,这两个变量应该在哪里相乘什么都没有发生(梯度的值没有改变)并且在下一行CUDA调试器告诉我:“'derivation'在目标位置没有值”

gradient * 2.0 可以正常工作,它会改变梯度值 2 次。

谁能帮帮我?

【问题讨论】:

    标签: c++ c cuda gpu multiplication


    【解决方案1】:
    a = pow(euler, neuron_device[startIndex + idx].outputValue);
    b = pow(euler, -neuron_device[startIndex + idx].outputValue);
    derivation = pow((2/(a + b),2);
    

    Pow 在以下情况下会出错:

    • 底数为负指数不是整数值,或
    • 基数为零,指数为,出现域错误,将全局变量 errno 设置为值 EDOM。

    我猜你正面临精度问题,'a''b' 都是 0。您可能会收到derivation = 0"inf"

    你能把浮点数改成双精度数吗?

    【讨论】:

      猜你喜欢
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      相关资源
      最近更新 更多