Skip to content

Commit

Permalink
fixfor avx update: removing vifelse
Browse files Browse the repository at this point in the history
  • Loading branch information
khosravipasha committed Mar 3, 2021
1 parent d3c9767 commit ce7f164
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/Logistic/parameters.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export learn_parameters, to_onehot

using CUDA
using LoopVectorization: @avx, vifelse

"""
LogisticCircuit Parameter learning through gradient descents
Expand Down Expand Up @@ -49,9 +48,9 @@ function update_parameters_cpu(bc, data, labels, cl, step_size)

@inline function on_edge_float(flows, values, prime, sub, element, grandpa, single_child, weights)
lock(params_lock) do # TODO: move lock to inner loop?
@avx for i = 1:size(flows, 1)
@simd for i = 1:size(flows, 1) # adding @avx here might give incorrect results
@inbounds edge_flow = values[i, prime] * values[i, sub] / values[i, grandpa] * flows[i, grandpa]
edge_flow = vifelse(isfinite(edge_flow), edge_flow, zero(eltype(flows)))
edge_flow = ifelse(isfinite(edge_flow), edge_flow, zero(eltype(flows)))
for class = 1:nc
@inbounds bc.parames[element, class] -= (cl[i, class] - labels[i, class]) * edge_flow * step_size
end
Expand Down
6 changes: 3 additions & 3 deletions src/Logistic/queries.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class_likelihood_per_instance, class_weights_per_instance

using CUDA
using LoopVectorization: @avx, vifelse
using LoopVectorization: @avx


"""
Expand Down Expand Up @@ -59,9 +59,9 @@ function class_weights_per_instance_cpu(bc, data)

@inline function on_edge_float(flows, values, prime, sub, element, grandpa, single_child, weights)
lock(cw_lock) do # TODO: move lock to inner loop?
@avx for i = 1:size(flows, 1)
@simd for i = 1:size(flows, 1) # adding @avx here might give incorrect results
@inbounds edge_flow = values[i, prime] * values[i, sub] / values[i, grandpa] * flows[i, grandpa]
edge_flow = vifelse(isfinite(edge_flow), edge_flow, zero(eltype(flows)))
edge_flow = ifelse(isfinite(edge_flow), edge_flow, zero(eltype(flows)))
for class = 1:nc
@inbounds cw[i, class] += edge_flow * bc.params[element, class]
end
Expand Down

0 comments on commit ce7f164

Please sign in to comment.