Skip to content

Commit

Permalink
Merge pull request #191 from clEsperanto/add-sub-region-copy
Browse files Browse the repository at this point in the history
enh: copy sub region of buffer and images
style: clean up execution and backend
  • Loading branch information
StRigaud authored Oct 6, 2023
2 parents 527e8ed + f8369ea commit ac6a1fe
Show file tree
Hide file tree
Showing 13 changed files with 730 additions and 523 deletions.
6 changes: 6 additions & 0 deletions clic/clic.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@
# include <nvrtc.h>
#endif

#if USE_OPENCL
const constexpr size_t GPU_MEM_PTR_SIZE = sizeof(cl_mem);
#else
const constexpr size_t GPU_MEM_PTR_SIZE = sizeof(void *);
#endif

#endif // __CLIC_HPP
34 changes: 18 additions & 16 deletions clic/include/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "device.hpp"
#include "utils.hpp"

#include <algorithm>
#include <variant>

namespace cle
{

Expand All @@ -22,22 +19,22 @@ class Array
return std::shared_ptr<Array>(new Array());
}
static auto
create(const size_t & width,
const size_t & height,
const size_t & depth,
create(size_t width,
size_t height,
size_t depth,
const dType & data_type,
const mType & mem_type,
const Device::Pointer & device_ptr) -> Array::Pointer;
static auto
create(const size_t & width,
const size_t & height,
const size_t & depth,
create(size_t width,
size_t height,
size_t depth,
const dType & data_type,
const mType & mem_type,
const void * host_data,
const Device::Pointer & device_ptr) -> Array::Pointer;
static auto
create(Array::Pointer array) -> Array::Pointer;
create(const Array::Pointer & array) -> Array::Pointer;

friend auto
operator<<(std::ostream & out, const Array::Pointer & array) -> std::ostream &;
Expand All @@ -52,21 +49,26 @@ class Array
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;
write(const void * host_data, size_t x_coord, size_t y_coord, 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;
read(void * host_data, size_t x_coord, size_t y_coord, size_t z_coord) const -> void;

auto
copy(const Array::Pointer & dst) const -> void;
auto
copy(const Array::Pointer & dst,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & src_origin,
const std::array<size_t, 3> & dst_origin) const -> void;

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

[[nodiscard]] auto
size() const -> size_t;
Expand Down Expand Up @@ -102,9 +104,9 @@ class Array
using MemoryPointer = std::shared_ptr<void *>;

Array() = default;
Array(const size_t & width,
const size_t & height,
const size_t & depth,
Array(size_t width,
size_t height,
size_t depth,
const dType & data_type,
const mType & mem_type,
const Device::Pointer & device_ptr);
Expand Down
197 changes: 115 additions & 82 deletions clic/include/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include "utils.hpp"

#include <algorithm>
#include <map>
#include <memory>
#include <array>
#include <vector>

namespace cle
Expand Down Expand Up @@ -74,33 +73,45 @@ class Backend


virtual auto
copyMemoryBufferToBuffer(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void = 0;
copyMemoryBufferToBuffer(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void = 0;
virtual auto
copyMemoryImageToBuffer(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void = 0;
copyMemoryImageToBuffer(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void = 0;
virtual auto
copyMemoryBufferToImage(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void = 0;
copyMemoryBufferToImage(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void = 0;
virtual auto
copyMemoryImageToImage(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void = 0;
copyMemoryImageToImage(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void = 0;

virtual auto
setMemory(const Device::Pointer & device,
Expand Down Expand Up @@ -226,33 +237,45 @@ class CUDABackend : public Backend
void * host_ptr) const -> void override;

auto
copyMemoryBufferToBuffer(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void override;
auto
copyMemoryImageToBuffer(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void override;
auto
copyMemoryBufferToImage(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void override;
auto
copyMemoryImageToImage(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void override;
copyMemoryBufferToBuffer(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void override;
auto
copyMemoryImageToBuffer(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void override;
auto
copyMemoryBufferToImage(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void override;
auto
copyMemoryImageToImage(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void override;

auto
setMemory(const Device::Pointer & device,
Expand Down Expand Up @@ -383,37 +406,47 @@ class OpenCLBackend : public Backend
const mType & mtype,
void * host_ptr) const -> void override;

auto
copyMemoryBufferToBuffer(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void override;

auto
copyMemoryImageToBuffer(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void override;

auto
copyMemoryBufferToImage(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void override;

auto
copyMemoryImageToImage(const Device::Pointer & device,
const void ** src_data_ptr,
const std::array<size_t, 3> & region,
const std::array<size_t, 3> & origin,
const size_t & bytes,
void ** dst_data_ptr) const -> void override;
copyMemoryBufferToBuffer(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void override;
auto
copyMemoryImageToBuffer(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void override;
auto
copyMemoryBufferToImage(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void override;
auto
copyMemoryImageToImage(const Device::Pointer & device,
const void ** src_ptr,
std::array<size_t, 3> & src_origin,
std::array<size_t, 3> & src_shape,
void ** dst_ptr,
std::array<size_t, 3> & dst_origin,
std::array<size_t, 3> & dst_shape,
std::array<size_t, 3> & region,
const size_t & bytes) const -> void override;

auto
setMemory(const Device::Pointer & device,
Expand Down
Loading

0 comments on commit ac6a1fe

Please sign in to comment.