chapel
chapel copied to clipboard
[Feature Request]: Support `complex` numbers in GPU kernels
We currently have limited-to-no support for using complex
numbers in a GPU kernel.
I tried a number of simple cases with complex numbers to get an idea of where our support is at. All tests are done with CHPL_GPU=nvidia
, except where otherwise noted.
What Works
Using existing complex numbers
use Math;
on here.gpus[0] {
var Arr: [1..10] complex;
@assertOnGpu
foreach i in 1..10 {
Arr[i] = 1+10i;
}
writeln(Arr);
}
This program actually does work! The immediate can also be factored outside the kernel and it will still work.
What doesn't work
Creating complex numbers from ints/reals
use Math;
on here.gpus[0] {
var Arr: [1..10] complex;
@assertOnGpu
foreach i in 1..10 {
Arr[i] = i:complex;
}
writeln(Arr);
}
This code fails because the cast to complex involves _chpl_complex128
, which is not as a GPU eligible extern function. So assertOnGpu fails with "ChapelTuple.chpl:295: note: function calls out to extern function (_chpl_complex128), which is not marked as GPU eligible".
Complex math
use Math;
on here.gpus[0] {
var Arr: [1..10] complex;
const c = -1-2i;
@assertOnGpu
foreach i in 1..10 {
Arr[i] = 1+10i + c;
}
writeln(Arr);
}
This program results in an internal error in the Chapel compiler during GPU compilation in the backend.
Calling math functions
use Math;
on here.gpus[0] {
var Arr: [1..10] complex;
const c = 2+2i;
@assertOnGpu
foreach i in 1..10 {
Arr[i] = sin(c);
}
writeln(Arr);
}
This program fails at codegen time with CHPL_GPU=nvidia when ptxas
is being invoked with "ptxas fatal : Unresolved extern function 'csin'".
I tried this same code with CHPL_GPU=amd, here it fails as "lld: error: undefined hidden symbol: csin".
Similar errors occur with other Math functions