Do a function like relu need a kernel ? When you need to write a GPU kernel rather than "just" using CuArray?

sylvaticus
Wed, 26 Jun 2024 14:28:39 +0000
GPU

The relu function works elementwise by returning the input that is non-negative, i.e. relu(x) = ifelse.(x .> 0, x, 0).

Does the fact that it works elementwise means I need to write a GPU kernel for it, or I can simply use CUArrays on it ?
Or perhaps I need to convert it to relu!(y,x) = begin y .= ifelse.(x .> 0, x, 0); return nothing end ?

Also, if I am writing a package and I have no idea if the user has a CPU or a specific GPU, how can I write code that works independently of the hardware, such that the user may have data in a standard Array, a CuArray, a ROCArray, oneArray or MtlArray… and she just calls the function (my function) and the computation is done on the appropriate hardware ?

4 posts - 4 participants