Skip to content

Commit 093b6b1

Browse files
committed
Incorporate LoopVectorization.@turbo into evaluation scheme
1 parent cc313ad commit 093b6b1

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.3.0"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
8+
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
89
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
910
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1011
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

src/EvaluateEquation.jl

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module EvaluateEquationModule
22

3+
import LoopVectorization: @turbo, indices
34
import ..EquationModule: Node, string_tree
45
import ..OperatorEnumModule: OperatorEnum, GenericOperatorEnum
56
import ..UtilsModule: @return_on_false, is_bad_array, vals
@@ -132,8 +133,8 @@ function deg2_eval(
132133
op = operators.binops[op_idx]
133134

134135
# We check inputs (and intermediates), not outputs.
135-
@inbounds @simd for j in 1:n
136-
x = op(cumulator[j], array2[j])::T
136+
@turbo for j in indices(cumulator)
137+
x = op(cumulator[j], array2[j])
137138
cumulator[j] = x
138139
end
139140
# return (cumulator, finished_loop) #
@@ -148,8 +149,8 @@ function deg1_eval(
148149
@return_on_false complete cumulator
149150
@return_on_nonfinite_array cumulator T n
150151
op = operators.unaops[op_idx]
151-
@inbounds @simd for j in 1:n
152-
x = op(cumulator[j])::T
152+
@turbo for j in indices(cumulator)
153+
x = op(cumulator[j])
153154
cumulator[j] = x
154155
end
155156
return (cumulator, true) #
@@ -191,9 +192,9 @@ function deg1_l2_ll0_lr0_eval(
191192
@return_on_check val_ll T n
192193
feature_lr = tree.l.r.feature
193194
cumulator = Array{T,1}(undef, n)
194-
@inbounds @simd for j in 1:n
195-
x_l = op_l(val_ll, cX[feature_lr, j])::T
196-
x = isfinite(x_l) ? op(x_l)::T : T(Inf) # These will get discovered by _eval_tree_array at end.
195+
@turbo for j in indices((cX, cumulator), (2, 1))
196+
x_l = op_l(val_ll, cX[feature_lr, j])
197+
x = isfinite(x_l) ? op(x_l) : T(Inf) # These will get discovered by _eval_tree_array at end.
197198
cumulator[j] = x
198199
end
199200
return (cumulator, true)
@@ -202,19 +203,19 @@ function deg1_l2_ll0_lr0_eval(
202203
val_lr = tree.l.r.val::T
203204
@return_on_check val_lr T n
204205
cumulator = Array{T,1}(undef, n)
205-
@inbounds @simd for j in 1:n
206-
x_l = op_l(cX[feature_ll, j], val_lr)::T
207-
x = isfinite(x_l) ? op(x_l)::T : T(Inf)
206+
@turbo for j in indices((cX, cumulator), (2, 1))
207+
x_l = op_l(cX[feature_ll, j], val_lr)
208+
x = isfinite(x_l) ? op(x_l) : T(Inf)
208209
cumulator[j] = x
209210
end
210211
return (cumulator, true)
211212
else
212213
feature_ll = tree.l.l.feature
213214
feature_lr = tree.l.r.feature
214215
cumulator = Array{T,1}(undef, n)
215-
@inbounds @simd for j in 1:n
216-
x_l = op_l(cX[feature_ll, j], cX[feature_lr, j])::T
217-
x = isfinite(x_l) ? op(x_l)::T : T(Inf)
216+
@turbo for j in indices((cX, cumulator), (2, 1))
217+
x_l = op_l(cX[feature_ll, j], cX[feature_lr, j])
218+
x = isfinite(x_l) ? op(x_l) : T(Inf)
218219
cumulator[j] = x
219220
end
220221
return (cumulator, true)
@@ -243,9 +244,9 @@ function deg1_l1_ll0_eval(
243244
else
244245
feature_ll = tree.l.l.feature
245246
cumulator = Array{T,1}(undef, n)
246-
@inbounds @simd for j in 1:n
247-
x_l = op_l(cX[feature_ll, j])::T
248-
x = isfinite(x_l) ? op(x_l)::T : T(Inf)
247+
@turbo for j in indices((cX, cumulator), (2, 1))
248+
x_l = op_l(cX[feature_ll, j])
249+
x = isfinite(x_l) ? op(x_l) : T(Inf)
249250
cumulator[j] = x
250251
end
251252
return (cumulator, true)
@@ -270,25 +271,25 @@ function deg2_l0_r0_eval(
270271
val_l = tree.l.val::T
271272
@return_on_check val_l T n
272273
feature_r = tree.r.feature
273-
@inbounds @simd for j in 1:n
274-
x = op(val_l, cX[feature_r, j])::T
274+
@turbo for j in indices((cX, cumulator), (2, 1))
275+
x = op(val_l, cX[feature_r, j])
275276
cumulator[j] = x
276277
end
277278
elseif tree.r.constant
278279
cumulator = Array{T,1}(undef, n)
279280
feature_l = tree.l.feature
280281
val_r = tree.r.val::T
281282
@return_on_check val_r T n
282-
@inbounds @simd for j in 1:n
283-
x = op(cX[feature_l, j], val_r)::T
283+
@turbo for j in indices((cX, cumulator), (2, 1))
284+
x = op(cX[feature_l, j], val_r)
284285
cumulator[j] = x
285286
end
286287
else
287288
cumulator = Array{T,1}(undef, n)
288289
feature_l = tree.l.feature
289290
feature_r = tree.r.feature
290-
@inbounds @simd for j in 1:n
291-
x = op(cX[feature_l, j], cX[feature_r, j])::T
291+
@turbo for j in indices((cX, cumulator), (2, 1))
292+
x = op(cX[feature_l, j], cX[feature_r, j])
292293
cumulator[j] = x
293294
end
294295
end
@@ -306,14 +307,14 @@ function deg2_l0_eval(
306307
if tree.l.constant
307308
val = tree.l.val::T
308309
@return_on_check val T n
309-
@inbounds @simd for j in 1:n
310-
x = op(val, cumulator[j])::T
310+
@turbo for j in indices(cumulator)
311+
x = op(val, cumulator[j])
311312
cumulator[j] = x
312313
end
313314
else
314315
feature = tree.l.feature
315-
@inbounds @simd for j in 1:n
316-
x = op(cX[feature, j], cumulator[j])::T
316+
@turbo for j in indices((cX, cumulator), (2, 1))
317+
x = op(cX[feature, j], cumulator[j])
317318
cumulator[j] = x
318319
end
319320
end
@@ -331,14 +332,14 @@ function deg2_r0_eval(
331332
if tree.r.constant
332333
val = tree.r.val::T
333334
@return_on_check val T n
334-
@inbounds @simd for j in 1:n
335-
x = op(cumulator[j], val)::T
335+
@turbo for j in indices(cumulator)
336+
x = op(cumulator[j], val)
336337
cumulator[j] = x
337338
end
338339
else
339340
feature = tree.r.feature
340-
@inbounds @simd for j in 1:n
341-
x = op(cumulator[j], cX[feature, j])::T
341+
@turbo for j in indices((cX, cumulator), (2, 1))
342+
x = op(cumulator[j], cX[feature, j])
342343
cumulator[j] = x
343344
end
344345
end

0 commit comments

Comments
 (0)