Skip to content

Commit

Permalink
Merge pull request #187 from clEsperanto/subregion-io
Browse files Browse the repository at this point in the history
Introduce region and origin into read and write operation. This allows to read and write sub region of a buffer.
  • Loading branch information
StRigaud authored Sep 29, 2023
2 parents 098a4d4 + fca15d7 commit 2c31f17
Show file tree
Hide file tree
Showing 9 changed files with 544 additions and 397 deletions.
18 changes: 17 additions & 1 deletion clic/include/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
namespace cle
{

class Array : public std::enable_shared_from_this<Array>
class Array
{
public:
using Pointer = std::shared_ptr<Array>;

static auto
New() -> Array::Pointer
{
Expand All @@ -41,14 +42,29 @@ class Array : public std::enable_shared_from_this<Array>
friend auto
operator<<(std::ostream & out, const Array::Pointer & array) -> std::ostream &;


auto
allocate() -> void;

auto
write(const void * host_data) -> void;
auto
write(const void * host_data, const std::array<size_t, 3> & region, const std::array<size_t, 3> & buffer_origin)
-> void;
auto
write(const void * host_data, const size_t & x_coord, const size_t & y_coord, const size_t & z_coord) -> void;

auto
read(void * host_data) const -> void;
auto
read(void * host_data, const std::array<size_t, 3> & region, const std::array<size_t, 3> & buffer_origin) const
-> void;
auto
read(void * host_data, const size_t & x_coord, const size_t & y_coord, const size_t & z_coord) const -> void;

auto
copy(const Array::Pointer & dst) const -> void;

auto
fill(const float & value) const -> void;

Expand Down
186 changes: 99 additions & 87 deletions clic/include/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,24 @@ class Backend
freeMemory(const Device::Pointer & device, const mType & mtype, void ** data_ptr) const -> void = 0;

virtual auto
writeMemory(const Device::Pointer & device,
void ** data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const mType & mtype,
const void * host_ptr) const -> void = 0;
writeMemory(const Device::Pointer & device,
void ** buffer_ptr,
std::array<size_t, 3> & buffer_shape,
std::array<size_t, 3> & buffer_origin,
std::array<size_t, 3> & region,
const dType & dtype,
const mType & mtype,
const void * host_ptr) const -> void = 0;

virtual auto
readMemory(const Device::Pointer & device,
const void ** data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const mType & mtype,
void * host_ptr) const -> void = 0;
readMemory(const Device::Pointer & device,
const void ** buffer_ptr,
std::array<size_t, 3> & buffer_shape,
std::array<size_t, 3> & buffer_origin,
std::array<size_t, 3> & region,
const dType & dtype,
const mType & mtype,
void * host_ptr) const -> void = 0;


virtual auto
Expand Down Expand Up @@ -101,13 +103,14 @@ class Backend
void ** dst_data_ptr) const -> void = 0;

virtual auto
setMemory(const Device::Pointer & device,
void ** data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const mType & mtype,
const float & value) const -> void = 0;
setMemory(const Device::Pointer & device,
void ** buffer_ptr,
std::array<size_t, 3> & buffer_shape,
std::array<size_t, 3> & buffer_origin,
std::array<size_t, 3> & region,
const dType & dtype,
const mType & mtype,
const float & value) const -> void = 0;

virtual auto
buildKernel(const Device::Pointer & device,
Expand Down Expand Up @@ -189,36 +192,38 @@ class CUDABackend : public Backend

static auto
writeBuffer(const Device::Pointer & device,
void ** data_ptr,
void ** buffer_ptr,
const std::array<size_t, 3> & buffer_shape,
const std::array<size_t, 3> & buffer_origin,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const void * host_ptr) -> void;
auto
writeMemory(const Device::Pointer & device,
void ** data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const mType & mtype,
const void * host_ptr) const -> void override;
writeMemory(const Device::Pointer & device,
void ** buffer_ptr,
std::array<size_t, 3> & buffer_shape,
std::array<size_t, 3> & buffer_origin,
std::array<size_t, 3> & region,
const dType & dtype,
const mType & mtype,
const void * host_ptr) const -> void override;

static auto
readBuffer(const Device::Pointer & device,
const void ** data_ptr,
const void ** buffer_ptr,
const std::array<size_t, 3> & buffer_shape,
const std::array<size_t, 3> & buffer_origin,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
void * host_ptr) -> void;

auto
readMemory(const Device::Pointer & device,
const void ** data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const mType & mtype,
void * host_ptr) const -> void override;
readMemory(const Device::Pointer & device,
const void ** buffer_ptr,
std::array<size_t, 3> & buffer_shape,
std::array<size_t, 3> & buffer_origin,
std::array<size_t, 3> & region,
const dType & dtype,
const mType & mtype,
void * host_ptr) const -> void override;

auto
copyMemoryBufferToBuffer(const Device::Pointer & device,
Expand Down Expand Up @@ -250,19 +255,21 @@ class CUDABackend : public Backend
void ** dst_data_ptr) const -> void override;

auto
setMemory(const Device::Pointer & device,
void ** data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const mType & mtype,
const float & value) const -> void override;
setMemory(const Device::Pointer & device,
void ** buffer_ptr,
std::array<size_t, 3> & buffer_shape,
std::array<size_t, 3> & buffer_origin,
std::array<size_t, 3> & region,
const dType & dtype,
const mType & mtype,
const float & value) const -> void override;

static auto
setBuffer(const Device::Pointer & device,
void ** data_ptr,
void ** buffer_ptr,
const std::array<size_t, 3> & buffer_shape,
const std::array<size_t, 3> & buffer_origin,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const float & value) -> void;

Expand Down Expand Up @@ -326,53 +333,55 @@ class OpenCLBackend : public Backend

static auto
writeBuffer(const Device::Pointer & device,
void ** data_ptr,
void ** buffer_ptr,
const std::array<size_t, 3> & buffer_shape,
const std::array<size_t, 3> & buffer_origin,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const void * host_ptr) -> void;

static auto
writeImage(const Device::Pointer & device,
void ** data_ptr,
void ** buffer_ptr,
const std::array<size_t, 3> & buffer_shape,
const std::array<size_t, 3> & buffer_origin,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const void * host_ptr) -> void;

auto
writeMemory(const Device::Pointer & device,
void ** data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const mType & mtype,
const void * host_ptr) const -> void override;
writeMemory(const Device::Pointer & device,
void ** buffer_ptr,
std::array<size_t, 3> & buffer_shape,
std::array<size_t, 3> & buffer_origin,
std::array<size_t, 3> & region,
const dType & dtype,
const mType & mtype,
const void * host_ptr) const -> void override;

static auto
readBuffer(const Device::Pointer & device,
const void ** data_ptr,
const void ** buffer_ptr,
const std::array<size_t, 3> & buffer_shape,
const std::array<size_t, 3> & buffer_origin,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
void * host_ptr) -> void;

static auto
readImage(const Device::Pointer & device,
const void ** data_ptr,
const void ** buffer_ptr,
const std::array<size_t, 3> & buffer_shape,
const std::array<size_t, 3> & buffer_origin,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
void * host_ptr) -> void;

auto
readMemory(const Device::Pointer & device,
const void ** data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const mType & mtype,
void * host_ptr) const -> void override;
readMemory(const Device::Pointer & device,
const void ** buffer_ptr,
std::array<size_t, 3> & buffer_shape,
std::array<size_t, 3> & buffer_origin,
std::array<size_t, 3> & region,
const dType & dtype,
const mType & mtype,
void * host_ptr) const -> void override;

auto
copyMemoryBufferToBuffer(const Device::Pointer & device,
Expand Down Expand Up @@ -407,27 +416,30 @@ class OpenCLBackend : public Backend
void ** dst_data_ptr) const -> void override;

auto
setMemory(const Device::Pointer & device,
void ** data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const mType & mtype,
const float & value) const -> void override;
setMemory(const Device::Pointer & device,
void ** buffer_ptr,
std::array<size_t, 3> & buffer_shape,
std::array<size_t, 3> & buffer_origin,
std::array<size_t, 3> & region,
const dType & dtype,
const mType & mtype,
const float & value) const -> void override;

static auto
setImage(const Device::Pointer & device,
void ** data_ptr,
void ** buffer_ptr,
const std::array<size_t, 3> & buffer_shape,
const std::array<size_t, 3> & buffer_origin,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const float & value) -> void;

static auto
setBuffer(const Device::Pointer & device,
void ** data_ptr,
void ** buffer_ptr,
const std::array<size_t, 3> & buffer_shape,
const std::array<size_t, 3> & buffer_origin,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const dType & dtype,
const float & value) -> void;

Expand Down
6 changes: 1 addition & 5 deletions clic/include/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ using KernelInfo = std::pair<std::string, std::string>;
using RangeArray = std::array<size_t, 3>;

auto
replaceWord(std::string & sentence, const std::string_view & wordToReplace, const std::string_view & replacement)
-> void;

auto
srcOpenclToCuda(const std::string & opencl_code) -> std::string;
translateOpenclToCuda(std::string & code) -> void;

auto
cudaDefines(const ParameterList & parameter_list, const ConstantList & constant_list) -> std::string;
Expand Down
Loading

0 comments on commit 2c31f17

Please sign in to comment.