Is it possible to create a virtual environment using CUDA?


I am trying to use julia 1.2.0 on a remote GPU system and I am having trouble creating a virtual environment where I can add the packages I need. These are the packages available in the remote machine:

(v1.2) pkg> status
    Status `/usr/local/share/julia/environments/v1.2/Project.toml`
  [3895d2a7] CUDAapi v1.2.0
  [c5f51814] CUDAdrv v4.0.2
  [be33ccc6] CUDAnative v2.5.1
  [3a865a2d] CuArrays v1.4.1

I don’t have admin privileges to add or update packages, but I’m assuming I can do that in a virtual environment.

All the tutorials I’ve found on creating virtual environments require adding a package like Playground.jl or VirtualEnv.jl. Is it possible to create a virtual environment using the versions of CUDA I have listed above?

Any advice or thoughts are welcomed!

First, is there any particular reason you’re stuck using Julia v1.2? That’s several years old at this point and basically unsupported - the current long-term support version is v1.6. Using an old version of Julia also prevents you from using modern versions of Julia’s CUDA stack - I’d highly recommend upgrading to at least Julia v1.6.

Julia’s built-in package manager supports environments by default, so you shouldn’t need any external package. Briefly:

julia> cd(mktempdir())

(@v1.8) pkg> activate CUDATestProject # enter Pkg mode with the ] key
  Activating new project at `C:\Users\alexa\AppData\Local\Temp\jl_gcrbSw\CUDATestProject`

(CUDATestProject) pkg> add CUDA
    Updating registry at `C:\Users\alexa\.julia\registries\General.toml`
   Resolving package versions...
   Installed GPUArraysCore ─ v0.1.0

julia> using CUDA

julia> @time sum(CUDA.rand(10^8)) # CUDA is downloaded at time of first use
  Downloaded artifact: CUDA
145.488497 seconds (30.93 M allocations: 2.484 GiB, 0.50% gc time, 4.94% compilation time)

julia> @time sum(CUDA.rand(10^8))
  0.093087 seconds (145 allocations: 7.844 KiB)

Unfortunately, I am stuck with julia v1.2.0 for now. I’ll ask our IT if they can update their julia version. But your suggestion worked for me. Many thanks!

julia> mktempdir(tempdir())

(v1.2) pkg> activate CUDATestProject
Activating new environment at `~/CUDATestProject/Project.toml`

(CUDATestProject) pkg> add BenchmarkTools
 Resolving package versions...
  Updating `~/CUDATestProject/Project.toml`
  [6e4b80f9] + BenchmarkTools v0.4.3
  Updating `~/CUDATestProject/Manifest.toml`
  [6e4b80f9] + BenchmarkTools v0.4.3
  [682c06a0] + JSON v0.21.0
  [69de0a69] + Parsers v0.3.8
  [2a0f44e3] + Base64
  [ade2ca70] + Dates
  [8ba89e20] + Distributed
  [b77e0a4c] + InteractiveUtils
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [a63ad114] + Mmap
  [de0858da] + Printf
  [9a3f8284] + Random
  [9e88b42a] + Serialization
  [6462fe0b] + Sockets
  [2f01184e] + SparseArrays
  [10745b16] + Statistics
  [8dfed614] + Test
  [4ec0a83e] + Unicode

You can just download and extract an archive containing Julia to your home folder or wherever, it doesn’t need any installation.