Skip to content

Commit 260a4dd

Browse files
authored
Implement sincos intrinsic to fix exp. (#443)
1 parent 49255ab commit 260a4dd

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/device/opencl/math.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@ for gentype in generic_types
9090
@device_function rsqrt(x::$gentype) = @builtin_ccall("rsqrt", $gentype, ($gentype,), x)
9191

9292
@device_override Base.sin(x::$gentype) = @builtin_ccall("sin", $gentype, ($gentype,), x)
93-
# sincos(x::$gentype, $gentype *cosval) = @builtin_ccall("sincos", $gentype, ($gentype, $gentype *), x, cosval)
93+
@device_override function Base.sincos(x::$gentype)
94+
cosval = Ref{$gentype}()
95+
sinval = GC.@preserve cosval begin
96+
ptr = Base.unsafe_convert(Ptr{$gentype}, cosval)
97+
llvm_ptr = reinterpret(LLVMPtr{$gentype, AS.Private}, ptr)
98+
@builtin_ccall("sincos", $gentype, ($gentype, LLVMPtr{$gentype, AS.Private}), x, llvm_ptr)
99+
end
100+
return sinval, cosval[]
101+
end
94102
@device_override Base.sinh(x::$gentype) = @builtin_ccall("sinh", $gentype, ($gentype,), x)
95103
@device_function sinpi(x::$gentype) = @builtin_ccall("sinpi", $gentype, ($gentype,), x)
96104

src/device/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ macro builtin_ccall(name, ret, argtypes, args...)
6363
# XXX: where does the V come from?
6464
"P" * ASstr * "V" * mangle(elt)
6565
else
66-
error("Unknown type $t")
66+
error("Unknown type $T")
6767
end
6868
end
6969

test/device/intrinsics.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ end
3737

3838
end
3939
end
40+
41+
@testset "exp" begin
42+
@test testf(a->exp.(a), Matrix{ComplexF32}([1.0 + 1.0im 1.0 - 1.0im; -1.0 + 1.0im -1.0 - 1.0im]))
43+
44+
end
4045
end
4146

4247

0 commit comments

Comments
 (0)