JuliaAttic / CUDArt.jl

Julia wrapper for CUDA runtime API
Other
79 stars 29 forks source link

Types with CudaArray elements cannot be saved to JLD because of pointer exception #40

Open denizyuret opened 8 years ago

denizyuret commented 8 years ago

I'd like to fix this so people can save and load machine learning models that use CudaArray's without having to explicitly copy everything to cpu. Is the right way to overwrite serialize - deserialize? Or is it to introduce a new cpu array type that CudaArrays know to convert themselves to and from during load/save? Or is there some other way?

timholy commented 8 years ago

See https://github.com/JuliaLang/JLD.jl/blob/master/doc/jld.md#custom-serialization

denizyuret commented 8 years ago

Thanks Tim, the following three lines solved the problem:

    type _CudaArraySave; a::Array; end
    JLD.writeas(c::CudaArray) = _CudaArraySave(to_host(c))
    JLD.readas(d::_CudaArraySave) = CudaArray(d.a)

Do you want to put this in CUDArt? I was going to submit a pull request but I couldn't be sure if you wanted JLD to be a requirement for CUDArt. In either case, this issue can be closed.

timholy commented 8 years ago

If you can come up with a solution that exploits Requires.jl, do you think that would be better?