autumnai / collenchyma

Extendable HPC-Framework for CUDA, OpenCL and common CPU
http://autumnai.github.io/collenchyma
Apache License 2.0
475 stars 33 forks source link

Add convenient access to underlying memory of a SharedTensor #33

Open MichaelHirn opened 8 years ago

MichaelHirn commented 8 years ago

Unwrapping a SharedTensor to get access to one of its memory copies is a tedious process at the moment, with a lot of unwrapping, tmp variables and boilerplate. As pointed out in the PR of the NN Plugin, this leads to all sort of inconvenient trouble.

alexandermorozov commented 8 years ago

I think there are 3 most often used classes of methods:

1) Initialization on creation of SharedTensor. Methods like from_slice(&dims, &slice), from_iter(&dims, &iter) would be most useful,

2) Overwriting after creation: .copy_from_slice() and .copy_from_iter().

3) Generic access with slices: read_slice(), write_only_slice(), read_write_slice(). Those methods would be implemented as thin wrappers on top read(&native_device) / write_only(&native_device) / read_write(&native_device). This cathegory includes first two, but having them would still be very convinient.

It's not very clear how 1) and 2) should behave on slices and iterators of incorrect length. Panic or return Result with error? Maybe initialization from longer iterators should still be allowed for convinience...