开发者

malloc a complex<float> in C++ and CUDA

开发者 https://www.devze.com 2023-02-07 02:57 出处:网络
In C++, if I want an array of complex I might do 开发者_JAVA百科something like this: complex<float> *temp = new complex<float>[size];

In C++, if I want an array of complex I might do 开发者_JAVA百科something like this:

complex<float> *temp = new complex<float>[size];

Can I change this into a malloc statement?

What about if I want to use cudaMalloc to give me an array on the GPU of complex floats?

thanks


Can I change this into a malloc statement?

No, but you can change it into a malloc statement with Placement-New. Can't see why you'd want to do that though.

What about if I want to use cudaMalloc to give me an array on the GPU of complex floats?

Again, you'll have to use placement new.


For Cuda there is the type cuComplex for complex floa values and cuDoubleComplex for double complex values. You can use both in combination with cudaMalloc or cublasAlloc.


Unless complex has no constructor, no. You should use new when allocating arrays in C++.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号