# How to use Float64 with GPU backend

**URL:** <https://itensor.discourse.group/t/how-to-use-float64-with-gpu-backend/2490>\
**Category:** ITensor Julia Questions\
**Tags:** julia\
**Created:** [September 10, 2025, 2:29pm UTC](https://itensor.discourse.group/t/how-to-use-float64-with-gpu-backend/2490 "2025-09-10T14:29:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ang](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ang/32/808_2.png) [@Ang](https://itensor.discourse.group/u/Ang)\
**Post date:** [September 10, 2025, 2:29pm UTC](https://itensor.discourse.group/t/how-to-use-float64-with-gpu-backend/2490/1 "2025-09-10T14:29:17Z")

</div>

I need Float64 precision for high-accuracy computations on GPU, but I haven’t been able to find relevant documentation or discussions on how to switch from Float32 to Float64 in ITensor. For reference, here’s a minimal example:

```auto
using ITensors, ITensorMPS
using Random: Random
using CUDA
using cuTENSOR

device_id = 0
CUDA.device!(device_id)

function main(; dtype=Float64, device=identity)
    Random.seed!(1234)

    L = 2

    H = OpSum()
    H += 1.0, "Sz", 1, "Sz", 2
    
    sites = siteinds("S=1/2", L)
    H_MPO = device(MPO(dtype, H, sites))
    
    psi_init = device(random_mps(dtype, sites; linkdims=10))
    outputlevel = 0

    nsweeps = 50
    maxdim = [10]
    cutoff = [1E-10]

    E, psi = dmrg(H_MPO, psi_init; nsweeps, maxdim, cutoff, outputlevel=outputlevel)
    
    println("Energy data type: ", typeof(E))
    flush(stdout)

    GC.gc()
    CUDA.reclaim()
end

main(;dtype=Float64, device=cu)

```

The printed energy data type is Float32, despite explicitly setting the data type of `psi_init` and `H_MPO` to Float64. This suggests that the DMRG algorithm is actually operating in Float32. Could someone clarify how to properly configure ITensor/ITensorMPS to use Float64 throughout the computation?

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [September 10, 2025, 2:36pm UTC](https://itensor.discourse.group/t/how-to-use-float64-with-gpu-backend/2490/2 "2025-09-10T14:36:57Z")

</div>

`cu(x)` defined in `CUDA.jl` automatically converts the element type to single precision (`Float32`). In order to preserve the element type, you can use `adapt(CuArray, x)` using the `adapt` function from `Adapt.jl`. See [Memory management · CUDA.jl](https://cuda.juliagpu.org/stable/usage/memory/#Type-preserving-upload) (that’s not anything specific to the design of ITensors.jl or ITensorMPS.jl, we are just following the design and conventions of the Julia GPU libraries).

**EDIT:** A trick you can use is calling your `main` function as `main(; dtype=Float64, device=adapt(CuArray))`, `adapt(CuArray)(x)` is equivalent to `adapt(CuArray, x)`.

---

<div class="post-metadata">

**Author:** ![Ang](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ang/32/808_2.png) [@Ang](https://itensor.discourse.group/u/Ang)\
**Post date:** [September 11, 2025, 3:56am UTC](https://itensor.discourse.group/t/how-to-use-float64-with-gpu-backend/2490/3 "2025-09-11T03:56:54Z")

</div>

This works perfectly! Thank you for your reply.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/d3072b13e047cd06df7f3981547c0917d940dfa4.png) [@system](https://itensor.discourse.group/u/system)\
**Post date:** [September 21, 2025, 3:57am UTC](https://itensor.discourse.group/t/how-to-use-float64-with-gpu-backend/2490/4 "2025-09-21T03:57:15Z")

</div>

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