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