Skip to content

Commit

Permalink
Merge pull request #182 from clEsperanto/update-backend-struct
Browse files Browse the repository at this point in the history
style: clean backend function call
fix: cuda bug when dst shape was (1,1,1)
rm: array support for cuda (for now)
add:  buffer Rect in ocl
add: origin arg for future
  • Loading branch information
StRigaud authored Sep 12, 2023
2 parents 560381f + afb67d8 commit 1199296
Show file tree
Hide file tree
Showing 11 changed files with 966 additions and 727 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.20)

project(CLIc VERSION 0.7.2)

set(BUILD_CUDA_BACKEND ON CACHE BOOL "Build CUDA backend")
set(BUILD_OPENCL_BACKEND ON CACHE BOOL "Build OpenCL backend")

# set environment variables
include(${PROJECT_SOURCE_DIR}/cmake/CMakeSetEnv.cmake)
# find library dependencies
Expand Down
479 changes: 268 additions & 211 deletions clic/include/backend.hpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clic/include/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ replaceWord(std::string & sentence, const std::string_view & wordToReplace, cons
-> void;

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

auto
cudaDefines(const ParameterList & parameter_list, const ConstantList & constant_list) -> std::string;
Expand Down
4 changes: 2 additions & 2 deletions clic/include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ loadFile(const std::string & file_path) -> std::string
}

inline auto
saveFile(std::string & file_path, std::string & source) -> void
saveFile(const std::string & file_path, const std::string & source) -> void
{
std::ofstream ofs(file_path);
if (!ofs.is_open())
Expand All @@ -237,7 +237,7 @@ saveFile(std::string & file_path, std::string & source) -> void
}

inline auto
correct_range(int * start, int * stop, int * step, size_t size) -> void
correct_range(int * start, int * stop, int * step, int size) -> void
{
// # set in case not set (passed None)
if (step == nullptr)
Expand Down
49 changes: 13 additions & 36 deletions clic/src/array.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "array.hpp"
#include <array>

namespace cle
{
Expand Down Expand Up @@ -82,14 +83,7 @@ Array::allocate() -> void
std::cerr << "Warning: Array is already initialized" << std::endl;
return;
}
if (mtype() == mType::IMAGE)
{
backend_.allocateMemory(device(), this->width(), this->height(), this->depth(), dtype(), get());
}
else
{
backend_.allocateMemory(device(), nbElements() * bytesPerElements(), get());
}
backend_.allocateMemory(device(), { this->width(), this->height(), this->depth() }, dtype(), mtype(), get());
initialized_ = true;
}

Expand All @@ -100,14 +94,8 @@ Array::write(const void * host_data) -> void
{
allocate();
}
if (mtype() == mType::IMAGE)
{
backend_.writeMemory(device(), get(), this->width(), this->height(), this->depth(), bytesPerElements(), host_data);
}
else
{
backend_.writeMemory(device(), get(), nbElements() * bytesPerElements(), host_data);
}
backend_.writeMemory(
device(), get(), { this->width(), this->height(), this->depth() }, { 0, 0, 0 }, dtype(), mtype(), host_data);
}

auto
Expand All @@ -117,14 +105,7 @@ Array::read(void * host_data) const -> void
{
throw std::runtime_error("Error: Array is not initialized, it cannot be read");
}
if (mtype() == mType::IMAGE)
{
backend_.readMemory(device(), c_get(), width(), height(), depth(), bytesPerElements(), host_data);
}
else
{
backend_.readMemory(device(), c_get(), nbElements() * bytesPerElements(), host_data);
}
backend_.readMemory(device(), c_get(), { width(), height(), depth() }, { 0, 0, 0 }, dtype(), mtype(), host_data);
}

auto
Expand All @@ -145,20 +126,23 @@ Array::copy(const Array::Pointer & dst) const -> void
}
if (mtype() == mType::BUFFER && dst->mtype() == mType::BUFFER)
{
backend_.copyMemoryBufferToBuffer(device(), c_get(), nbElements() * bytesPerElements(), dst->get());
backend_.copyMemoryBufferToBuffer(
device(), c_get(), { width(), height(), depth() }, { 0, 0, 0 }, toBytes(dtype()), dst->get());
}
else if (mtype() == mType::IMAGE && dst->mtype() == mType::IMAGE)
{
backend_.copyMemoryImageToImage(device(), c_get(), width(), height(), depth(), toBytes(dtype()), dst->get());
backend_.copyMemoryImageToImage(
device(), c_get(), { width(), height(), depth() }, { 0, 0, 0 }, toBytes(dtype()), dst->get());
}
else if (mtype() == mType::BUFFER && dst->mtype() == mType::IMAGE)
{
backend_.copyMemoryBufferToImage(
device(), c_get(), dst->width(), dst->height(), dst->depth(), toBytes(dst->dtype()), dst->get());
device(), c_get(), { width(), height(), depth() }, { 0, 0, 0 }, toBytes(dtype()), dst->get());
}
else if (mtype() == mType::IMAGE && dst->mtype() == mType::BUFFER)
{
backend_.copyMemoryImageToBuffer(device(), c_get(), width(), height(), depth(), toBytes(dtype()), dst->get());
backend_.copyMemoryImageToBuffer(
device(), c_get(), { width(), height(), depth() }, { 0, 0, 0 }, toBytes(dtype()), dst->get());
}
else
{
Expand All @@ -173,14 +157,7 @@ Array::fill(const float & value) const -> void
{
std::cerr << "Error: Arrays are not initialized_" << std::endl;
}
if (mtype() == mType::IMAGE)
{
backend_.setMemory(device(), get(), width(), height(), depth(), value, dtype());
}
else
{
backend_.setMemory(device(), get(), nbElements() * bytesPerElements(), value, dtype());
}
backend_.setMemory(device(), get(), { width(), height(), depth() }, { 0, 0, 0 }, dtype(), mtype(), value);
}

auto
Expand Down
Loading

0 comments on commit 1199296

Please sign in to comment.