Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Last active November 3, 2017 12:10
Show Gist options
  • Save SimonDanisch/87409265ea5788e7fbf0f7ba74b211a1 to your computer and use it in GitHub Desktop.
Save SimonDanisch/87409265ea5788e7fbf0f7ba74b211a1 to your computer and use it in GitHub Desktop.
using GPUArrays
# Overloading the Julia Base map! function for GPUArrays
function Base.map!(f::Function, A::GPUArray, B::GPUArray)
# the below is the Julia syntax to create a closure and pass it
# as the first argument to gpu_call
gpu_call(A, (f, A, B)) do state, f, A, B
# If launch parameters arent specified, linear_index gets the index
# into the Array passed as second argument to gpu_call (`A`)
i = linear_index(state)
A[i] = f(B[i])
return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment