Saving CUDA MPS to HDF5

Hi all!

First of all, I would like to say that I’ve been using ITensor a lot in the first couple months of my PhD, and it’s been a great experience!

While doing DMRG calculations on the GPU using the CUDA backend, I encountered a problem:
I cannot save an MPS which is on the GPU to a hdf5 file.
Is this not implemented, or am I doing something wrong?
Here’s a minimal bit of code to reproduce this issue:

using ITensors, ITensorMPS
using HDF5
using CUDA

sites = siteinds("S=1/2", 5, conserve_qns=false)

psi_random = random_mps(sites;linkdims=5)
psi_random_gpu = cu(psi_random)

fi = h5open("test.h5","cw")
write(fi, "MPS", psi_random) #Saving CPU MPS to hdf5, works fine
write(fi, "MPS_GPU", psi_random_gpu) #Saving GPU MPS to hdf5, throws error
close(fi)

It throws the following error:
ERROR: ArgumentError: Illegal conversion of a CUDA.DeviceMemory to a Ptr{Float32}

A possible fix would be to move the psi_random_gpu (the GPU MPS) back onto the CPU, though I could not find how to do this.

Thanks in advance!
Pim

I resolved the issue! After posting this, I encountered the following post:

https://itensor.discourse.group/t/bring-mps-from-gpu-back-to-cpu/

There is indeed a way to move the MPS from GPU back to the CPU, using NDTensors.cpu()

This works perfectly!

1 Like

Glad to hear it. Thanks for updating you post with the solution!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.