CUDA device index is not forwarded to the grad tensor
Context
I'm working on allowing CUDA based training in AIDGE on any device, but I'm facing several difficulties with the device index handling.
Problem
When setting a tensor backend, we must ensure that the backend of its gradient tensor is properly set too, and this actually the case.
But the same should apply to the device index, and in practice this is not the case : the device index stays at zero !
Reproduce
To reproduce the problem one could use the following block of code ...
Note : to execute this code one should pybind the device()
method
import numpy as np
import aidge_core
import aidge_backend_cpu
import aidge_backend_cuda
array = np.random.rand(4, 4)
tensor = aidge_core.Tensor(array)
tensor.set_datatype(aidge_core.dtype.float32)
tensor.set_backend('cuda', 3)
print(tensor.backend(), tensor.device())
print(tensor.grad().backend(), tensor.grad().device()) # <- device is still 0 !
returns :
cuda 3
cuda 0
EDIT : Solved by !445 (merged)
Edited by Benjamin Halimi