aboutsummaryrefslogtreecommitdiff
path: root/compute_kernel_writer/src/cl/helpers/CLMemoryOpImage2dHelper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'compute_kernel_writer/src/cl/helpers/CLMemoryOpImage2dHelper.cpp')
-rw-r--r--compute_kernel_writer/src/cl/helpers/CLMemoryOpImage2dHelper.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/compute_kernel_writer/src/cl/helpers/CLMemoryOpImage2dHelper.cpp b/compute_kernel_writer/src/cl/helpers/CLMemoryOpImage2dHelper.cpp
index 55f88f4136..b7d146bdee 100644
--- a/compute_kernel_writer/src/cl/helpers/CLMemoryOpImage2dHelper.cpp
+++ b/compute_kernel_writer/src/cl/helpers/CLMemoryOpImage2dHelper.cpp
@@ -28,11 +28,11 @@
#include "ckw/types/MemoryOperation.h"
#include "ckw/types/TensorStorageType.h"
-#include "src/ITensor.h"
-#include "src/Tensor3dMapper.h"
#include "src/cl/CLKernelWriter.h"
#include "src/cl/CLTensorArgument.h"
#include "src/cl/CLTile.h"
+#include "src/ITensor.h"
+#include "src/Tensor3dMapper.h"
namespace ckw
{
@@ -66,31 +66,36 @@ void CLMemoryOpImage2dHelper::finalize()
{
}
-bool CLMemoryOpImage2dHelper::validate(const CLKernelWriter *writer, const ITensor *tensor, const TensorSampler *sampler, const Tensor3dMapper *mapper, MemoryOperation op, const CLTile *dst)
+bool CLMemoryOpImage2dHelper::validate(const CLKernelWriter *writer,
+ const ITensor *tensor,
+ const TensorSampler *sampler,
+ const Tensor3dMapper *mapper,
+ MemoryOperation op,
+ const CLTile *dst)
{
CKW_UNUSED(writer, tensor, mapper);
- if(dst->info().width() != 4)
+ if (dst->info().width() != 4)
{
return false;
}
- if(sampler->address_mode_x() != TensorSamplerAddressModeX::None)
+ if (sampler->address_mode_x() != TensorSamplerAddressModeX::None)
{
return false;
}
- if(sampler->address_mode_z() != TensorSamplerAddressModeZ::None)
+ if (sampler->address_mode_z() != TensorSamplerAddressModeZ::None)
{
return false;
}
- if(sampler->storage() != TensorStorageType::Texture2dReadOnly && op == MemoryOperation::Load)
+ if (sampler->storage() != TensorStorageType::Texture2dReadOnly && op == MemoryOperation::Load)
{
return false;
}
- if(sampler->storage() != TensorStorageType::Texture2dWriteOnly && op == MemoryOperation::Store)
+ if (sampler->storage() != TensorStorageType::Texture2dWriteOnly && op == MemoryOperation::Store)
{
return false;
}
- if((dst->info().data_type() != DataType::Fp32) && (dst->info().data_type() != DataType::Fp16))
+ if ((dst->info().data_type() != DataType::Fp32) && (dst->info().data_type() != DataType::Fp16))
{
return false;
}
@@ -102,7 +107,7 @@ void CLMemoryOpImage2dHelper::out_of_bound_initialize_y(const std::string &coord
CKW_UNUSED(coord);
const TensorSamplerAddressModeY address_mode_y = _sampler->address_mode_y();
- switch(address_mode_y)
+ switch (address_mode_y)
{
case TensorSamplerAddressModeY::SkipLessThanZero:
_writer->op_write_raw_code("if(" + coord + " >= 0)\n{\n");
@@ -118,7 +123,7 @@ void CLMemoryOpImage2dHelper::out_of_bound_initialize_y(const std::string &coord
void CLMemoryOpImage2dHelper::out_of_bound_finalize_y()
{
const TensorSamplerAddressModeY address_mode_y = _sampler->address_mode_y();
- switch(address_mode_y)
+ switch (address_mode_y)
{
case TensorSamplerAddressModeY::SkipLessThanZero:
_writer->op_write_raw_code("}\n");
@@ -131,15 +136,19 @@ void CLMemoryOpImage2dHelper::out_of_bound_finalize_y()
}
}
-std::string CLMemoryOpImage2dHelper::to_ls_image2d(MemoryOperation op, int32_t vector_width, const std::string &data, const std::string &sampler, const std::string &address) const
+std::string CLMemoryOpImage2dHelper::to_ls_image2d(MemoryOperation op,
+ int32_t vector_width,
+ const std::string &data,
+ const std::string &sampler,
+ const std::string &address) const
{
CKW_UNUSED(vector_width);
const TensorStorageType tensor_storage = _sampler->storage();
- const std::string image2d_obj = _tensor->storage(tensor_storage).val;
- const std::string post_fix = _dst->info().data_type() == DataType::Fp32 ? "f" : "h";
+ const std::string image2d_obj = _tensor->storage(tensor_storage).val;
+ const std::string post_fix = _dst->info().data_type() == DataType::Fp32 ? "f" : "h";
- switch(op)
+ switch (op)
{
case MemoryOperation::Load:
return data + " = read_image" + post_fix + "(" + image2d_obj + ", " + sampler + ", " + address + ")";
@@ -155,7 +164,7 @@ std::string CLMemoryOpImage2dHelper::to_ls_image2d_sampler() const
{
const auto address_mode_y = _sampler->address_mode_y();
- switch(address_mode_y)
+ switch (address_mode_y)
{
case TensorSamplerAddressModeY::None:
return "CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST";
@@ -167,17 +176,19 @@ std::string CLMemoryOpImage2dHelper::to_ls_image2d_sampler() const
}
}
-std::string CLMemoryOpImage2dHelper::to_ls_image2d_address(const std::string &x, const std::string &y, const std::string &z,
+std::string CLMemoryOpImage2dHelper::to_ls_image2d_address(const std::string &x,
+ const std::string &y,
+ const std::string &z,
const std::string &b) const
{
std::string coord_x = "(" + x + ") >> 2";
std::string coord_y = "(";
- if(y != "0")
+ if (y != "0")
{
coord_y += y;
}
- if(z != "0" && (_mapper->dim_z().str != "1"))
+ if (z != "0" && (_mapper->dim_z().str != "1"))
{
const std::string dim = _mapper->dim_y().str;
coord_y += " + (";
@@ -185,7 +196,7 @@ std::string CLMemoryOpImage2dHelper::to_ls_image2d_address(const std::string &x,
coord_y += " * ";
coord_y += dim;
}
- if(b != "0" && (_mapper->dim_batch().str != "1"))
+ if (b != "0" && (_mapper->dim_batch().str != "1"))
{
const std::string dim0 = _mapper->dim_y().str;
const std::string dim1 = _mapper->dim_z().str;