diff --git a/src/cuda/GPUField.h b/src/cuda/GPUField.h index 437fe1c9523f8bed311fc3410a4a0d268f9a610b..116071a6505a11be9e186c0172ad6f00c1259251 100755 --- a/src/cuda/GPUField.h +++ b/src/cuda/GPUField.h @@ -133,6 +133,9 @@ namespace cuda { void * data() { return pitchedPtr_.ptr; } const void * data() const { return pitchedPtr_.ptr; } + T * dataAt(cell_idx_t x, cell_idx_t y, cell_idx_t z, cell_idx_t f); + const T * dataAt(cell_idx_t x, cell_idx_t y, cell_idx_t z, cell_idx_t f) const; + protected: cudaPitchedPtr pitchedPtr_; uint_t nrOfGhostLayers_; diff --git a/src/cuda/GPUField.impl.h b/src/cuda/GPUField.impl.h index b6fe3f8a87b08d424dd055a13401925b98fafc42..946afd7ae7fbc016b6fc43123539f9bef960ad62 100644 --- a/src/cuda/GPUField.impl.h +++ b/src/cuda/GPUField.impl.h @@ -67,6 +67,26 @@ GPUField<T>::~GPUField() cudaFree( pitchedPtr_.ptr ); } +template<typename T> +T * GPUField<T>::dataAt(cell_idx_t x, cell_idx_t y, cell_idx_t z, cell_idx_t f) +{ + auto offset = (x + nrOfGhostLayers_) * xStride() + + (y + nrOfGhostLayers_) * yStride() + + (z + nrOfGhostLayers_) * zStride() + + f * fStride(); + return static_cast<T*>(pitchedPtr_.ptr) + offset; +} + +template<typename T> +const T * GPUField<T>::dataAt(cell_idx_t x, cell_idx_t y, cell_idx_t z, cell_idx_t f) const +{ + auto offset = (x + nrOfGhostLayers_) * xStride() + + (y + nrOfGhostLayers_) * yStride() + + (z + nrOfGhostLayers_) * zStride() + + f * fStride(); + return static_cast<T*>(pitchedPtr_.ptr) + offset; +} + template<typename T> void GPUField<T>::getGhostRegion(stencil::Direction d, CellInterval & ci, diff --git a/src/field/Field.h b/src/field/Field.h index c7785e80ef0006e8cb2703751c2f6f8870579dfe..b6e517ec3d1f774c2c372757a2423ced83e84ec5 100644 --- a/src/field/Field.h +++ b/src/field/Field.h @@ -291,6 +291,8 @@ namespace field { //@{ T * data() { return values_; } const T * data() const { return values_; } + T * dataAt(cell_idx_t x, cell_idx_t y, cell_idx_t z, cell_idx_t f) { return &get(x,y,z,f); } + const T * dataAt(cell_idx_t x, cell_idx_t y, cell_idx_t z, cell_idx_t f) const { return &get(x,y,z,f); } T * dataInner() { return valuesWithOffset_; } const T * dataInner() const { return valuesWithOffset_; }