# ITensorGPU installation and usage

**URL:** <https://itensor.discourse.group/t/itensorgpu-installation-and-usage/784>\
**Category:** ITensor Julia Questions\
**Tags:** julia\
**Created:** [April 19, 2023, 11:54am UTC](https://itensor.discourse.group/t/itensorgpu-installation-and-usage/784 "2023-04-19T11:54:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![raffaele](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/raffaele/32/136_2.png) [@raffaele](https://itensor.discourse.group/u/raffaele)\
**Post date:** [April 19, 2023, 11:54am UTC](https://itensor.discourse.group/t/itensorgpu-installation-and-usage/784/1 "2023-04-19T11:54:44Z")

</div>

Hi All, I am trying to install and use ITensorGPU but without success.  
I can install CUDA and cuTENSOR, and the test of the two packes is fine.  
I can install ITensorGPU but for some reaons it cannot use cuTENSOR.

 ![image](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/c7457f78ffd6f54c30ad032c8fabc229e411a584.png)

Below is the output of my CUDA.versioninfo

julia\> CUDA.versioninfo()  
CUDA runtime 11.8, artifact installation  
CUDA driver 12.1  
NVIDIA driver 530.30.2

Libraries:

- CUBLAS: 11.11.3
- CURAND: 10.3.0
- CUFFT: 10.9.0
- CUSOLVER: 11.4.1
- CUSPARSE: 11.7.5
- CUPTI: 18.0.0
- NVML: 12.0.0+530.30.2

Toolchain:

- Julia: 1.8.5
- LLVM: 13.0.1
- PTX ISA support: 3.2, 4.0, 4.1, 4.2, 4.3, 5.0, 6.0, 6.1, 6.3, 6.4, 6.5, 7.0, 7.1, 7.2
- Device capability support: sm\_37, sm\_50, sm\_52, sm\_53, sm\_60, sm\_61, sm\_62, sm\_70, sm\_72, sm\_75, sm\_80, sm\_86

1 device:  
0: NVIDIA A40 (sm\_86, 44.398 GiB / 44.988 GiB available)

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![raffaele](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/raffaele/32/136_2.png) [@raffaele](https://itensor.discourse.group/u/raffaele)\
**Post date:** [April 19, 2023, 12:29pm UTC](https://itensor.discourse.group/t/itensorgpu-installation-and-usage/784/2 "2023-04-19T12:29:28Z")

</div>

Two more comments about the problem.

If I check the CUDA installation following the instructions on the ITensorGPU page, I get:

> using CUDA.CUTENSOR  
> ERROR: UndefVarError: CUTENSOR not defined

Yet if I run the ITensorGPU tests one by one they all succeed:  
julia\> include(“.julia/packages/ITensorGPU/x16B1/test/test\_cuitensor.jl”)  
Test Summary: | Pass Total Time  
cuITensor, Dense{Float64} storage | 327752 327752 1m33.1s  
Test Summary: | Pass Total Time  
cuITensor, Dense{ComplexF64} storage | 327752 327752 46.7s

---

<div class="post-metadata">

**Author:** ![raffaele](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/raffaele/32/136_2.png) [@raffaele](https://itensor.discourse.group/u/raffaele)\
**Post date:** [April 20, 2023, 1:49pm UTC](https://itensor.discourse.group/t/itensorgpu-installation-and-usage/784/3 "2023-04-20T13:49:40Z")

</div>

Anyone that can help?

---

<div class="post-metadata">

**Author:** ![kmp5](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/kmp5/32/251_2.png) [@kmp5](https://itensor.discourse.group/u/kmp5)\
**Post date:** [April 20, 2023, 4:45pm UTC](https://itensor.discourse.group/t/itensorgpu-installation-and-usage/784/4 "2023-04-20T16:45:40Z")

</div>

Hello @raffaele, I am currently working to fix the ITensorGPU tests. What your seeing is an artifact of `Pkg.test()` This function creates a new activated temporary directory when you call `Pkg.test("ITensorGPU")` and ignores the `LocalPreferences.jl` file created when you call `CUDA.set_runtime_version!`. There are a couple of ways to avoid this issue for now:

1. If you run the tests using `include("path/to/ITensorGPU/tests/runtests.jl")` This can fix the problem. or
2. If you grab the latest version of ITensorGPU, we restrict the version of `CUDA.jl` to `v4.0` which downloads `CUDA runtime v11` instead of `v12.1` (which is what the latest `CUDA@4.1.4` uses).

To answer your other question: there is no longer a `CUDA.CUTENSOR` package. The `cuTENSOR` portion of `CUDA.jl` was recently moved to its own project with the name change `CUTENSOR -> cuTENSOR`. To call CUDA with cuTENSOR use the julia commands

```auto
using CUDA
using cuTENSOR

```

Can you please forward me the information about which test fails?

---

<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:** [April 20, 2023, 7:36pm UTC](https://itensor.discourse.group/t/itensorgpu-installation-and-usage/784/5 "2023-04-20T19:36:14Z")

</div>

@raffaele, to zoom out from the issue trying to get the tests to pass when running `Pkg.test`, are you able to use `ITensorGPU` effectively to run calculations, for example can you run DMRG on GPU (without QN symmetries)? If so, the issue is likely just a problem with how the tests are interpreting the CUDA version, as @kmp5 is describing, and not fundamentally an issue with your ability to use the package for your project.

---

<div class="post-metadata">

**Author:** ![raffaele](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/raffaele/32/136_2.png) [@raffaele](https://itensor.discourse.group/u/raffaele)\
**Post date:** [April 21, 2023, 9:35am UTC](https://itensor.discourse.group/t/itensorgpu-installation-and-usage/784/6 "2023-04-21T09:35:55Z")

</div>

Thank you very much for the explanation. Including the file directly does indeed work. Only 6 tests are broken, all from the test\_cudiag.jl

> include(“.julia/packages/ITensorGPU/x16B1/test/test\_cudiag.jl”)  
> Test Summary: | Pass Broken Total Time  
> cuITensor Float64 Contractions | 5 1 6 0.0s  
> Test Summary: | Pass Broken Total Time  
> cuITensor ComplexF64 Contractions | 5 1 6 0.0s  
> Test Summary: | Pass Broken Total Time  
> cuITensor Float64, Float64 Contractions | 5 1 6 0.0s  
> Test Summary: | Pass Broken Total Time  
> cuITensor Float64, ComplexF64 Contractions | 5 1 6 0.0s  
> Test Summary: | Pass Broken Total Time  
> cuITensor ComplexF64, Float64 Contractions | 5 1 6 0.0s  
> Test Summary: | Pass Broken Total Time  
> cuITensor ComplexF64, ComplexF64 Contractions | 5 1 6 0.0s  
> 4-element Vector{Any}:  
> Test.DefaultTestSet(“cuITensor Float64, Float64 Contractions”, Any[Test.DefaultTestSet(“Test contract cuITensors”, Any[Test.DefaultTestSet(“Test contract cuITensors (Matrix_Diag → Matrix)", Any[], 1, false, false, true, 1.682069467152939e9, 1.682069467153417e9), Test.DefaultTestSet("Test contract cuDiagITensors (Diag_Diag → Diag)”, Any, 1, false, false, true, 1.682069467153428e9, 1.682069467153549e9), Test.DefaultTestSet(“Test contract cuDiagITensors (UniformDiag_Diag → Diag)", Any[], 2, false, false, true, 1.682069467153556e9, 1.682069467153844e9), Test.DefaultTestSet("Test contract cuITensors (Matrix_UniformDiag → Matrix)”, Any[Test Broken  
> Expression: ≈(collect(cC), array(2.0 \* cpu(replaceind(permute(Aij, j, i), i, i’))), atol = 0.0001)], 1, false, false, true, 1.682069467153851e9, 1.682069467154175e9)], 0, false, false, true, 1.68206946715276e9, 1.682069467154176e9)], 0, false, false, true, 1.682069467152742e9, 1.682069467154178e9)  
> Test.DefaultTestSet(“cuITensor Float64, ComplexF64 Contractions”, Any[Test.DefaultTestSet(“Test contract cuITensors”, Any[Test.DefaultTestSet(“Test contract cuITensors (Matrix_Diag → Matrix)", Any[], 1, false, false, true, 1.682069467155263e9, 1.682069467155577e9), Test.DefaultTestSet("Test contract cuDiagITensors (Diag_Diag → Diag)”, Any, 1, false, false, true, 1.682069467155584e9, 1.682069467155702e9), Test.DefaultTestSet(“Test contract cuDiagITensors (UniformDiag_Diag → Diag)", Any[], 2, false, false, true, 1.68206946715573e9, 1.682069467155946e9), Test.DefaultTestSet("Test contract cuITensors (Matrix_UniformDiag → Matrix)”, Any[Test Broken  
> Expression: ≈(collect(cC), array(2.0 \* cpu(replaceind(permute(Aij, j, i), i, i’))), atol = 0.0001)], 1, false, false, true, 1.682069467155952e9, 1.682069467156641e9)], 0, false, false, true, 1.682069467155171e9, 1.682069467156642e9)], 0, false, false, true, 1.682069467155165e9, 1.682069467156645e9)  
> Test.DefaultTestSet(“cuITensor ComplexF64, Float64 Contractions”, Any[Test.DefaultTestSet(“Test contract cuITensors”, Any[Test.DefaultTestSet(“Test contract cuITensors (Matrix_Diag → Matrix)", Any[], 1, false, false, true, 1.682069467157307e9, 1.682069467157562e9), Test.DefaultTestSet("Test contract cuDiagITensors (Diag_Diag → Diag)”, Any, 1, false, false, true, 1.682069467157568e9, 1.682069467157669e9), Test.DefaultTestSet(“Test contract cuDiagITensors (UniformDiag_Diag → Diag)", Any[], 2, false, false, true, 1.682069467157675e9, 1.6820694671579e9), Test.DefaultTestSet("Test contract cuITensors (Matrix_UniformDiag → Matrix)”, Any[Test Broken  
> Expression: ≈(collect(cC), array(2.0 \* cpu(replaceind(permute(Aij, j, i), i, i’))), atol = 0.0001)], 1, false, false, true, 1.682069467157905e9, 1.68206946716124e9)], 0, false, false, true, 1.682069467157227e9, 1.682069467161244e9)], 0, false, false, true, 1.682069467157221e9, 1.682069467161247e9)  
> Test.DefaultTestSet(“cuITensor ComplexF64, ComplexF64 Contractions”, Any[Test.DefaultTestSet(“Test contract cuITensors”, Any[Test.DefaultTestSet(“Test contract cuITensors (Matrix_Diag → Matrix)", Any[], 1, false, false, true, 1.682069467163772e9, 1.682069467164366e9), Test.DefaultTestSet("Test contract cuDiagITensors (Diag_Diag → Diag)”, Any, 1, false, false, true, 1.682069467164383e9, 1.682069467164601e9), Test.DefaultTestSet(“Test contract cuDiagITensors (UniformDiag_Diag → Diag)", Any[], 2, false, false, true, 1.682069467164612e9, 1.682069467165051e9), Test.DefaultTestSet("Test contract cuITensors (Matrix_UniformDiag → Matrix)”, Any[Test Broken  
> Expression: ≈(collect(cC), array(2.0 \* cpu(replaceind(permute(Aij, j, i), i, i’))), atol = 0.0001)], 1, false, false, true, 1.682069467165063e9, 1.682069467167379e9)], 0, false, false, true, 1.682069467163555e9, 1.682069467167382e9)], 0, false, false, true, 1.68206946716354e9, 1.682069467167383e9)
