CUDA/AMD/CPU device agnostic array creation best practice

Marcell_Havlik
Sun, 23 Jan 2022 09:34:27 +0000
General Usage

Dear Julianners,

What is the best practice to do a device agnostic array initialisation.
I believe this package written by many person already.

For example:

get_worker_type() = :CUDA # This is actually a function that get's the context of the worker... But for simplicity.
move2hw(arr) = get_worker_type() == :CUDA ? cu(arr) : arr  # also extended with AMD array...
move2hw(arr, device=:CPU) = device == :CUDA ? cu(arr) : arr

I think there should be a best practice at initialising the arrays on the right device. I used Symbol but I know this should be compilation time, so definitely will switch to that.

I believe 10 or 100 of us wrote the switch cases like that… But didn’t find a simple package that solve this issue yet.

10 posts - 3 participants