Skip to content

Commit

Permalink
style: clean headers
Browse files Browse the repository at this point in the history
  • Loading branch information
StRigaud committed Oct 4, 2023
1 parent 956f6ea commit c7de244
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions clic/include/device.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef __INCLUDE_DEVICE_HPP
#define __INCLUDE_DEVICE_HPP

#include "clic.hpp"

#include <iostream>
#include <map>
#include <memory>
#include <sstream>

#include "clic.hpp"

namespace cle
{
class Device
Expand Down
4 changes: 1 addition & 3 deletions clic/src/array.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "array.hpp"
#include <array>

namespace cle
{
Expand All @@ -17,7 +16,6 @@ Array::Array(const size_t width,
, memType_(mem_type)
, device_(device_ptr)
, data_(std::make_shared<void *>(nullptr))
, initialized_(false)
{}

Array::~Array()
Expand Down Expand Up @@ -56,7 +54,7 @@ Array::create(const size_t width,
}

auto
Array::create(Array::Pointer array) -> Array::Pointer
Array::create(const Array::Pointer & array) -> Array::Pointer
{
auto ptr = create(array->width(), array->height(), array->depth(), array->dtype(), array->mtype(), array->device());
array->copy(ptr);
Expand Down
5 changes: 0 additions & 5 deletions clic/src/cudabackend.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "backend.hpp"
#include "cle_preamble_cu.h"
#include <array>
#include <chrono>

namespace cle
{
Expand Down Expand Up @@ -756,9 +754,6 @@ CUDABackend::buildKernel(const Device::Pointer & device,
std::to_string(err) + ").");
}

std::chrono::high_resolution_clock::time_point start_time, end_time;
std::chrono::microseconds duration;

CUmodule cuModule = nullptr;
std::string hash = std::to_string(std::hash<std::string>{}(kernel_source));
loadProgramFromCache(device, hash, &cuModule);
Expand Down
21 changes: 12 additions & 9 deletions clic/src/execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
#include "backend.hpp"
#include "clic.hpp"

// #include <fstream>
// #include <string_view>
// #include <vector>

namespace cle
{

Expand All @@ -31,11 +27,12 @@ translateOpenclToCuda(std::string & code) -> void
};

// list of replacements to be performed (not exhaustive)
// special case: 'make_' need to followed by ');' replacement, e.g. (int2){1,2}; -> make_int2(1,2);
const std::vector<std::pair<std::string, std::string>> replacements = {
{ "(int2){", "make_int2(" }, // special case - need to followed by ');' replacement
{ "(int4){", "make_int4(" }, // special case - need to followed by ');' replacement
{ "(float4){", "make_float4(" }, // special case - need to followed by ');' replacement
{ "(float2){", "make_float2(" }, // special case - need to followed by ');' replacement
{ "(int2){", "make_int2(" },
{ "(int4){", "make_int4(" },
{ "(float4){", "make_float4(" },
{ "(float2){", "make_float2(" },
{ "__constant sampler_t", "__device__ int" },
{ "inline", "__device__ inline" },
{ "#pragma", "// #pragma" },
Expand Down Expand Up @@ -113,6 +110,8 @@ arrayDefines(const ParameterList & parameter_list, const Device::Type & device)
static constexpr std::array<const char *, 3> ndimMap = { "1", "2", "3" };
static constexpr std::array<const char *, 3> posTypeMap = { "int", "int2", "int4" };
static constexpr std::array<const char *, 3> posMap = { "(pos0)", "(pos0, pos1)", "(pos0, pos1, pos2, 0)" };

// loop over all parameters, skip if parameter is not an array
for (const auto & param : parameter_list)
{
if (std::holds_alternative<const float>(param.second) || std::holds_alternative<const int>(param.second))
Expand All @@ -122,6 +121,7 @@ arrayDefines(const ParameterList & parameter_list, const Device::Type & device)
const auto & arr = std::get<Array::Pointer>(param.second);
const auto & key = param.first;

// manage array dimension
const size_t dimIndex = arr->dim() - 1;
const std::string ndim = ndimMap[dimIndex];
const std::string pos_type = posTypeMap[dimIndex];
Expand All @@ -134,7 +134,8 @@ arrayDefines(const ParameterList & parameter_list, const Device::Type & device)
defines << "\n#define POS_" << param.first << "_INSTANCE(pos0,pos1,pos2,pos3) " << prefix << pos;
defines << "\n";

if (arr->mtype() == mType::BUFFER)
// manage array type (buffer or image), and read/write macros
if (arr->mtype() == mType::BUFFER || device == Device::Type::CUDA)
{
std::string ocl_keyword = (device == Device::Type::OPENCL) ? "__global " : "";
bufferDefines(defines, key, ndim, toString(arr->dtype()), arr->shortType(), ocl_keyword);
Expand All @@ -153,6 +154,8 @@ arrayDefines(const ParameterList & parameter_list, const Device::Type & device)
}
imageDefines(defines, key, ndim, arr->shortType(), access_type);
}

// manage array size
defines << "\n";
defines << "\n#define IMAGE_SIZE_" << key << "_WIDTH " << std::to_string(arr->width());
defines << "\n#define IMAGE_SIZE_" << key << "_HEIGHT " << std::to_string(arr->height());
Expand Down
3 changes: 2 additions & 1 deletion clic/src/openclbackend.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "backend.hpp"
#include "cle_preamble_cl.h"

#include <array>
#include <unordered_map>

namespace cle
{

#if USE_OPENCL
[[nodiscard]] static auto
getErrorString(const cl_int & error) -> std::string
{
Expand Down Expand Up @@ -62,6 +62,7 @@ getErrorString(const cl_int & error) -> std::string
auto ite = openCLErrorToStr.find(error);
return (ite != openCLErrorToStr.end()) ? ite->second : "CL_UNKNOWN_ERROR";
}
#endif

auto
OpenCLBackend::getDevices(const std::string & type) const -> std::vector<Device::Pointer>
Expand Down

0 comments on commit c7de244

Please sign in to comment.