Rewriting function on CPU for execution on GPU

I tried this Writing simple kernel functions (EM algorithm) - #7 by ennvvy. Also, the scalar indexing that I have highlighted, dont work! I get the following error:

scalar getindex is disallowed

Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] assertscalar(::String) at /root/.julia/packages/GPUArrays/0lvhc/src/indexing.jl:14
 [3] getindex at /root/.julia/packages/GPUArrays/0lvhc/src/indexing.jl:54 [inlined]
 [4] iterate at ./abstractarray.jl:914 [inlined]
 [5] iterate at ./abstractarray.jl:912 [inlined]
 [6] update!(::CuArray{Float32,1,Nothing}, ::CuArray{Float32,2,Nothing}, ::CuArray{Float32,1,Nothing}, ::CuArray{Float32,1,Nothing}, ::CuArray{Float32,1,Nothing}, ::CuArray{Float32,1,Nothing}, ::CuArray{Float32,1,Nothing}, ::CuArray{Float32,1,Nothing}, ::CuArray{Float32,1,Nothing}) at ./In[7]:25
 [7] ##core#472() at /root/.julia/packages/BenchmarkTools/7aqwe/src/execution.jl:297
 [8] ##sample#473(::BenchmarkTools.Parameters) at /root/.julia/packages/BenchmarkTools/7aqwe/src/execution.jl:303
 [9] #_run#8(::Bool, ::String, ::Base.Iterators.Pairs{Symbol,Integer,NTuple{4,Symbol},NamedTuple{(:samples, :evals, :gctrial, :gcsample),Tuple{Int64,Int64,Bool,Bool}}}, ::typeof(BenchmarkTools._run), ::BenchmarkTools.Benchmark{Symbol("##benchmark#471")}, ::BenchmarkTools.Parameters) at /root/.julia/packages/BenchmarkTools/7aqwe/src/execution.jl:331
 [10] (::Base.var"#inner#2"{Base.Iterators.Pairs{Symbol,Integer,NTuple{5,Symbol},NamedTuple{(:verbose, :samples, :evals, :gctrial, :gcsample),Tuple{Bool,Int64,Int64,Bool,Bool}}},typeof(BenchmarkTools._run),Tuple{BenchmarkTools.Benchmark{Symbol("##benchmark#471")},BenchmarkTools.Parameters}})() at ./none:0
 [11] #invokelatest#1 at ./essentials.jl:713 [inlined]
 [12] #invokelatest at ./none:0 [inlined]
 [13] #run_result#37 at /root/.julia/packages/BenchmarkTools/7aqwe/src/execution.jl:32 [inlined]
 [14] #run_result at ./none:0 [inlined]
 [15] #run#39(::Base.Iterators.Pairs{Symbol,Integer,NTuple{5,Symbol},NamedTuple{(:verbose, :samples, :evals, :gctrial, :gcsample),Tuple{Bool,Int64,Int64,Bool,Bool}}}, ::typeof(run), ::BenchmarkTools.Benchmark{Symbol("##benchmark#471")}, ::BenchmarkTools.Parameters) at /root/.julia/packages/BenchmarkTools/7aqwe/src/execution.jl:46
 [16] #run at ./none:0 [inlined] (repeats 2 times)
 [17] #warmup#42 at /root/.julia/packages/BenchmarkTools/7aqwe/src/execution.jl:79 [inlined]
 [18] warmup(::BenchmarkTools.Benchmark{Symbol("##benchmark#471")}) at /root/.julia/packages/BenchmarkTools/7aqwe/src/execution.jl:79
 [19] top-level scope at /root/.julia/packages/BenchmarkTools/7aqwe/src/execution.jl:390
 [20] top-level scope at In[9]:100: