0

I'm trying to make a function that uses CUDA. I want the function to load a string as a vector of bits, as suggested in this. The problem is that I'm not managing to load the object with the pointer. I get a code 700 error. Below is the code to replicate the error. My final goal is to perform comparisons between the strings.

using CUDA, InternedStrings
CUDA.allowscalar(false)

string_list = ["apple","banana","corn"]

vals = pointer.(intern.(string_list))

c = CuArray(vals)

function gpu_concatenate_strings(Arr1)
    
    index = threadIdx().x    
    stride = blockDim().x

    for i = index:stride:length(Arr1)
        test = unsafe_load(Arr1[i]) 
        
        @cuprint("test ", Int(test), "\n")
    end
    return
end

@cuda blocks=2 threads=2 gpu_concatenate_strings(c)
synchronize()
ERROR: CUDA error: an illegal memory access was encountered (code 700, ERROR_ILLEGAL_ADDRESS)
Stacktrace:
 [1] throw_api_error(res::CUDA.cudaError_enum)
   @ CUDA ~/.julia/packages/CUDA/tVtYo/lib/cudadrv/libcuda.jl:27
 [2] check
   @ ~/.julia/packages/CUDA/tVtYo/lib/cudadrv/libcuda.jl:34 [inlined]
 [3] cuStreamSynchronize
   @ ~/.julia/packages/CUDA/tVtYo/lib/utils/call.jl:26 [inlined]
 [4] synchronize(stream::CuStream; blocking::Nothing)
   @ CUDA ~/.julia/packages/CUDA/tVtYo/lib/cudadrv/stream.jl:134
 [5] synchronize
   @ ~/.julia/packages/CUDA/tVtYo/lib/cudadrv/stream.jl:123 [inlined]
 [6] synchronize()
   @ CUDA ~/.julia/packages/CUDA/tVtYo/lib/cudadrv/stream.jl:123
 [7] top-level scope
   @ Untitled-1:24

Edit: The function can be reduced to this form. The for loop on the function above is irrelevant.

function gpu_concatenate_strings(Arr1)
   test = unsafe_load(Arr1[i]) 
        
   @cuprint("test ", Int(test), "\n")

    return
end
  • 1
    (I don't know Julia) While this probably isn't the reason for the illegal access, I think every block is accessing the same elements right now. You want a grid-stride loop, i.e. `index = blockIdx().x * blockDim().x + threadIdx().x` and `stride = blockDim().x * gridDim().x`. – paleonix Jul 21 '23 at 21:35
  • I see, I didn't notice, I pasted the wrong bit of code. This bit is not relevant to the question I'll change it on the question. But I appreciate your comment. – Marco Aurélio Guerra Jul 21 '23 at 21:42

0 Answers0