Skip to content

Commit a2b5ec2

Browse files
authored
Use symbols instead of values when emitting code, when possible. (#1804)
1 parent 5b20411 commit a2b5ec2

File tree

8 files changed

+30
-30
lines changed

8 files changed

+30
-30
lines changed

lib/cublas/linalg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function gemv_dispatch!(Y::CuVector, A, B, alpha::Number=true, beta::Number=fals
182182
end
183183
end
184184

185-
for NT in (Number, Real)
185+
for NT in (:Number, :Real)
186186
# NOTE: alpha/beta also ::Real to avoid ambiguities with certain Base methods
187187
@eval begin
188188
LinearAlgebra.mul!(Y::CuVector, A::StridedCuMatrix, B::StridedCuVector, a::$NT, b::$NT) =
@@ -303,7 +303,7 @@ function gemm_dispatch!(C::CuVecOrMat, A, B, alpha::Number=true, beta::Number=fa
303303
end
304304
end
305305

306-
for NT in (Number, Real)
306+
for NT in (:Number, :Real)
307307
# NOTE: alpha/beta also ::Real to avoid ambiguities with certain Base methods
308308
@eval begin
309309
LinearAlgebra.mul!(C::CuMatrix, A::StridedCuVecOrMat, B::StridedCuVecOrMat, a::$NT, b::$NT) =

lib/cudadrv/memory.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ end
388388

389389
## copy operations
390390

391-
for (fn, srcPtrTy, dstPtrTy) in (("cuMemcpyDtoHAsync_v2", CuPtr, Ptr),
392-
("cuMemcpyHtoDAsync_v2", Ptr, CuPtr),
391+
for (fn, srcPtrTy, dstPtrTy) in (("cuMemcpyDtoHAsync_v2", :CuPtr, :Ptr),
392+
("cuMemcpyHtoDAsync_v2", :Ptr, :CuPtr),
393393
)
394394
@eval function Base.unsafe_copyto!(dst::$dstPtrTy{T}, src::$srcPtrTy{T}, N::Integer;
395395
stream::CuStream=stream(),

lib/cusparse/array.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ Base.copy(Mat::CuSparseMatrixCOO) = copyto!(similar(Mat), Mat)
510510

511511
# input/output
512512

513-
for (gpu, cpu) in [CuSparseVector => SparseVector]
513+
for (gpu, cpu) in [:CuSparseVector => :SparseVector]
514514
@eval function Base.show(io::IO, ::MIME"text/plain", x::$gpu)
515515
xnnz = length(nonzeros(x))
516516
print(io, length(x), "-element ", typeof(x), " with ", xnnz,
@@ -522,10 +522,10 @@ for (gpu, cpu) in [CuSparseVector => SparseVector]
522522
end
523523
end
524524

525-
for (gpu, cpu) in [CuSparseMatrixCSC => SparseMatrixCSC,
526-
CuSparseMatrixCSR => SparseMatrixCSC,
527-
CuSparseMatrixBSR => SparseMatrixCSC,
528-
CuSparseMatrixCOO => SparseMatrixCSC]
525+
for (gpu, cpu) in [:CuSparseMatrixCSC => :SparseMatrixCSC,
526+
:CuSparseMatrixCSR => :SparseMatrixCSC,
527+
:CuSparseMatrixBSR => :SparseMatrixCSC,
528+
:CuSparseMatrixCOO => :SparseMatrixCSC]
529529
@eval Base.show(io::IOContext, x::$gpu) =
530530
show(io, $cpu(x))
531531

lib/cusparse/conversions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ for SparseMatrixType in [:CuSparseMatrixCSC, :CuSparseMatrixCSR]
227227
end
228228

229229
# by flipping rows and columns, we can use that to get CSC to CSR too
230-
for elty in (Float32, Float64, ComplexF32, ComplexF64)
230+
for elty in (:Float32, :Float64, :ComplexF32, :ComplexF64)
231231
@eval begin
232232
function CuSparseMatrixCSC{$elty}(csr::CuSparseMatrixCSR{$elty}; index::SparseChar='O', action::cusparseAction_t=CUSPARSE_ACTION_NUMERIC, algo::cusparseCsr2CscAlg_t=CUSPARSE_CSR2CSC_ALG1)
233233
m,n = size(csr)

perf/volumerhs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ end
2020

2121
# HACK: module-local versions of core arithmetic; needed to get FMA
2222
for (jlf, f) in zip((:+, :*, :-), (:add, :mul, :sub))
23-
for (T, llvmT) in ((Float32, "float"), (Float64, "double"))
23+
for (T, llvmT) in ((:Float32, "float"), (:Float64, "double"))
2424
ir = """
2525
%x = f$f contract nsz $llvmT %0, %1
2626
ret $llvmT %x
@@ -38,7 +38,7 @@ for (jlf, f) in zip((:+, :*, :-), (:add, :mul, :sub))
3838
end
3939

4040
let (jlf, f) = (:div_arcp, :div)
41-
for (T, llvmT) in ((Float32, "float"), (Float64, "double"))
41+
for (T, llvmT) in ((:Float32, "float"), (:Float64, "double"))
4242
ir = """
4343
%x = f$f fast $llvmT %0, %1
4444
ret $llvmT %x

src/device/intrinsics/atomics.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ for T in (Int32, Int64, UInt32, UInt64)
8585
end
8686
end
8787

88-
for T in (Float32, Float64)
88+
for T in (:Float32, :Float64)
8989
ops = [:add]
9090

9191
for op in ops
@@ -135,13 +135,13 @@ end
135135
end
136136
end
137137

138-
for T in (Int32, Int64, UInt32, UInt64)
138+
for T in (:Int32, :Int64, :UInt32, :UInt64)
139139
@eval @inline atomic_cas!(ptr::LLVMPtr{$T}, cmp::$T, val::$T) =
140140
llvm_atomic_cas(ptr, cmp, val)
141141
end
142142

143143
# NVPTX doesn't support cmpxchg with i16 yet
144-
for A in (AS.Generic, AS.Global, AS.Shared), T in (Int16, UInt16)
144+
for A in (AS.Generic, AS.Global, AS.Shared), T in (:Int16, :UInt16)
145145
if A == AS.Global
146146
scope = ".global"
147147
elseif A == AS.Shared
@@ -182,7 +182,7 @@ end
182182

183183
# half-precision atomics using PTX instruction
184184

185-
for A in (AS.Generic, AS.Global, AS.Shared), T in (Float16,)
185+
for A in (AS.Generic, AS.Global, AS.Shared), T in (:Float16,)
186186
if A == AS.Global
187187
scope = ".global"
188188
elseif A == AS.Shared
@@ -207,7 +207,7 @@ inttype(::Type{Float32}) = Int32
207207
inttype(::Type{Float64}) = Int64
208208
inttype(::Type{BFloat16}) = Int16
209209

210-
for T in [Float16, Float32, Float64, BFloat16]
210+
for T in [:Float16, :Float32, :Float64, :BFloat16]
211211
@eval @inline function atomic_cas!(ptr::LLVMPtr{$T,A}, cmp::$T, new::$T) where {A}
212212
IT = inttype($T)
213213
cmp_i = reinterpret(IT, cmp)
@@ -445,13 +445,13 @@ end
445445
atomic_arrayset(A, Base._to_linear_index(A, Is...), op, convert(T, val))
446446

447447
# native atomics
448-
for (op,impl,typ) in [(+, atomic_add!, [UInt32,Int32,UInt64,Int64,Float32]),
449-
(-, atomic_sub!, [UInt32,Int32,UInt64,Int64,Float32]),
450-
(&, atomic_and!, [UInt32,Int32,UInt64,Int64]),
451-
(|, atomic_or!, [UInt32,Int32,UInt64,Int64]),
452-
(, atomic_xor!, [UInt32,Int32,UInt64,Int64]),
453-
(max, atomic_max!, [UInt32,Int32,UInt64,Int64]),
454-
(min, atomic_min!, [UInt32,Int32,UInt64,Int64])]
448+
for (op,impl,typ) in [(:(+), :(atomic_add!), [:UInt32,:Int32,:UInt64,:Int64,:Float32]),
449+
(:(-), :(atomic_sub!), [:UInt32,:Int32,:UInt64,:Int64,:Float32]),
450+
(:(&), :(atomic_and!), [:UInt32,:Int32,:UInt64,:Int64]),
451+
(:(|), :(atomic_or!), [:UInt32,:Int32,:UInt64,:Int64]),
452+
(:(), :(atomic_xor!), [:UInt32,:Int32,:UInt64,:Int64]),
453+
(:max, :(atomic_max!), [:UInt32,:Int32,:UInt64,:Int64]),
454+
(:min, :(atomic_min!), [:UInt32,:Int32,:UInt64,:Int64])]
455455
@eval @inline atomic_arrayset(A::AbstractArray{T}, I::Integer, ::typeof($op),
456456
val::T) where {T<:Union{$(typ...)}} =
457457
$impl(pointer(A, I), val)

src/device/intrinsics/wmma.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ for ops in all_ldst_ops,
193193

194194
ccall_name = "$llvm_intr"
195195

196-
ptr_ty = LLVMPtr{arr_ty, addr_space_int}
196+
ptr_ty = :(LLVMPtr{$arr_ty, $addr_space_int})
197197

198198
if sz == 1
199199
@eval $func_name(src_addr, stride) = tuple(ccall($ccall_name, llvmcall, $frag_ty, ($ptr_ty, Int32), src_addr, stride))
@@ -261,7 +261,7 @@ export llvm_wmma_store
261261
frag_types = ntuple(i -> frag_ty, sz)
262262
frag_vars = ntuple(i -> :(data[$i]), sz)
263263

264-
ptr_ty = LLVMPtr{arr_ty, addr_space_int}
264+
ptr_ty = :(LLVMPtr{$arr_ty, $addr_space_int})
265265

266266
@eval $func_name(dst_addr, data, stride) = ccall($ccall_name, llvmcall, Nothing, ($ptr_ty, $(frag_types...), Int32), dst_addr, $(frag_vars...), stride)
267267
@eval export $func_name

src/device/texture.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ end
5656
Base.Tuple(x::Vec4) = tuple(x.a, x.b, x.c, x.d)
5757

5858
for (dispatch_rettyp, julia_rettyp, llvm_rettyp) in
59-
((Signed, Vec4{UInt32}, :v4u32),
60-
(Unsigned, Vec4{Int32}, :v4s32),
61-
(AbstractFloat, Vec4{Float32}, :v4f32))
59+
((:Signed, :(Vec4{UInt32}), :v4u32),
60+
(:Unsigned, :(Vec4{Int32}), :v4s32),
61+
(:AbstractFloat, :(Vec4{Float32}), :v4f32))
6262

63-
eltyp = Union{dispatch_rettyp, NTuple{<:Any,dispatch_rettyp}}
63+
eltyp = :(Union{$dispatch_rettyp, NTuple{<:Any,$dispatch_rettyp}})
6464

6565
# tex1D only supports array memory
6666
@eval tex(texObject::CuDeviceTexture{<:$eltyp,1,ArrayMemory}, x::Number) =

0 commit comments

Comments
 (0)