cuComplex.h和exp() [英] cuComplex.h and exp()

查看:150
本文介绍了cuComplex.h和exp()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Q0:



cuComplex.h支持exp()吗?



Q1:



如何写A = B * exp(i * C),其中A,B,C是相同大小的实数数组?



main:

  cuComplex A; 
浮动B;
cuComplex c;

内核:

  c [idx] =(0,C [idx]); 

A [idx] = B [idx] * exp(c [idx]);

第二季度:



cuComplex包含2个浮点数数字,这意味着我必须为原始矩阵分配2倍的内存。有什么方法可以创建纯虚数? (CUBLAS和CUFFT库),则不支持指数函数。



您可以使用基于组件的算法自己实现指数。 cuComplex将复数的实部存储在x分量中,将虚部存储在y分量中。给定复数z = x + i * y,可以将指数计算为:



exp(z)= exp(x)*(cos(y)+ i * sin(y))



这会导致以下CUDA代码(未经测试):

  cuComplex my_complex_exp(cuComplex arg)
{
cuComplex res;
float s,c;
float e = expf(arg.x);
sincosf(arg.y,& s,& c);
res.x = c * e;
res.y = s * e;
美元的回报;
}


Q0:

Is exp() supported by cuComplex.h?

Q1:

How to write A = B * exp(i * C), where A, B, C are same size arrays of real numbers? Is this right?

main:

cuComplex A;
float B;
cuComplex c;

kernel:

c[idx] = ( 0, C[idx] );

A[idx] = B[idx] * exp( c[idx] ); 

Q2:

cuComplex contains 2 float numbers which means I have to allocate 2 times more memory then for original matrix. is there any way to create pure imaginary number?

解决方案

cuComplex.h only offers some basic operations on cuComplex (principally those used inside the CUBLAS and CUFFT libraries), the exponential function is not supported.

You can implement the exponential yourself using component-wise arithmetic. cuComplex stores the real part of a complex number in the x component and the imaginary part in the y component. Given a complex number z = x + i*y, the exponent can be computed as:

exp(z) = exp(x) * (cos(y) + i * sin(y))

This leads to the following CUDA code (untested):

cuComplex my_complex_exp (cuComplex arg)
{
   cuComplex res;
   float s, c;
   float e = expf(arg.x);
   sincosf(arg.y, &s, &c);
   res.x = c * e;
   res.y = s * e;
   return res;
}

这篇关于cuComplex.h和exp()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆