Can't install package CuArrays

Dear all,

I am trying to learn CUDA from the book “CUDA by Example” by Sanders and Kandrot. The book is based on C, so I am translating their examples to Julia. I got stuck at their example 3.2.3, which you can see here: https://github.com/yottaawesome/cuda-by-example/blob/master/src/chapter03/simple_kernel_params.cu

I wrote the Julia counterpart as this:

using CUDA

function add!(a :: Int64,
              b :: Int64,
              c :: CuDeviceVector{Int64})
  c[1] = a + b
  return nothing
end

function main()

  c     = zeros(Int64, 1);                    # variable on the host
  dev_c = CuArray{Int64}(undef, 1)            # variable on the device

  @cuda threads=1 blocks=1 add!(2, 7, dev_c)  # call GPU kernel function add!

  c = Array(dev_c)                            # copy from device's to host
  println("2 + 7 = ", c[1])                   # print the result

  CUDA.unsafe_free!(dev_c)                    # free the memory on the device

end

This works as expected, but I don’t like the line: c = Array(dev_c), I find it somehow non-intuitive. Instead, I tried to use CyArrays.copyto!(), but I get the error saying CuArrays were not defined. Command using CuArrays tells me that CuArrays were not installed, and suggest me to import the package the usual Julian way. However, importing the package results in the following error:

ERROR: Unsatisfiable requirements detected for package CUDAapi [3895d2a7]:
 CUDAapi [3895d2a7] log:
 ├─possible versions are: 0.5.0-4.0.0 or uninstalled
 ├─restricted by compatibility requirements with CuArrays [3a865a2d] to versions: 0.5.0-4.0.0
 │ └─CuArrays [3a865a2d] log:
 │   ├─possible versions are: 0.2.1-2.2.2 or uninstalled
 │   └─restricted to versions * by an explicit requirement, leaving only versions 0.2.1-2.2.2
 └─restricted by julia compatibility requirements to versions: uninstalled — no versions left

So I wonder: are CuArrays deprecated? How can one use command: CyArrays.copyto!(), unless it is deprecated too?

Cheers

Which Julia version are you using?

1.6.3

That won’t work, see here:

Apparently this is the “old CUDA stack” which shouldn’t be used on Julia >1.6. So this is probably just a case of an outdated example in the book - if you absolutely want to run it, you’d have to do so on Julia 1.5.4.

1 Like

Thanks!

Just use copyto!, there’s no need for a module prefix. The method you want to call is defined by the CUDA module, no need to use any of the old packages (like CuArrays.jl).