hash-grid-encoding icon indicating copy to clipboard operation
hash-grid-encoding copied to clipboard

RuntimeError,data type

Open AAAeray opened this issue 1 year ago • 2 comments

Hi there, Thanks for your great work, I tried your example,but it occurred: x1 = (x0 + 1).clamp(max=shape[1]-1) RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument max in method wrapper_CUDA_clamp_Tensor)

AAAeray avatar Jul 12 '24 05:07 AAAeray

Same problem

pxxxl avatar Sep 03 '24 02:09 pxxxl

The shape[1] is on cpu, while x0 on gpu. Hence, a possible fix is,

    max_val = torch.tensor(shape[1]-1, dtype=x0.dtype, device=x0.device)
    x1 = (x0 + 1).clamp(max=max_val)
    max_val = torch.tensor(shape[0]-1, dtype=y0.dtype, device=y0.device)
    y1 = (y0 + 1).clamp(max=max_val)

Alternatively, casting to integer is also fine,

    x1 = (x0 + 1).clamp(max=int(shape[1]-1))

I assume the newly added warning doesn't matter here.

PeterHUistyping avatar Nov 06 '25 15:11 PeterHUistyping