3

I have a lot of String operations to perform and I'd like to implement code in Julia 1.2.0 using GPU processing. Right off the bat I ran into issues defining a CuArray, an example is below. I essentially want to be able to hand a 1D Array of strings into a GPU kernal.

using CUDAnative 

using CuArrays

CuArray(["1","2","3"])

​

Type String does not have a definite size.

Stacktrace:
 [1] sizeof at .\essentials.jl:452 [inlined]
 [2] CuArray{String,1,P} where P(::UndefInitializer, ::Tuple{Int64}) at C:\Users\julul\.julia\packages\CuArrays\7z7MV\src\array.jl:90
 [3] Type at C:\Users\julul\.julia\packages\CuArrays\7z7MV\src\array.jl:174 [inlined]
 [4] CuArray(::Array{String,1}) at C:\Users\julul\.julia\packages\CuArrays\7z7MV\src\array.jl:188
 [5] top-level scope at In[24]:3
einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

3

Maybe someone will have a better idea but this is what I would try to do:

using CUDAnative 
using CuArrays
using InternedStrings
vals = pointer.(intern.(["1","2","33"]))
c = CuArray(vals) 

Note that without internalizing Strings different copies of the same String would point to different memory addresses and would not be able to do the Text Mining that you probably want to do. To make it more clear see the example below:

julia> CuArray(pointer.(intern.(["1","2","3"*"3"]))) == CuArray(pointer.(intern.(["1","2","33"])))
true

julia> CuArray(pointer.(["1","2","3"*"3"])) == CuArray(pointer.(["1","2","33"]))
false
Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62