aboutsummaryrefslogtreecommitdiff
path: root/compute_kernel_writer/prototype/examples
diff options
context:
space:
mode:
Diffstat (limited to 'compute_kernel_writer/prototype/examples')
-rw-r--r--compute_kernel_writer/prototype/examples/add_exp_store.cpp39
-rw-r--r--compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.cpp8
-rw-r--r--compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.h4
-rw-r--r--compute_kernel_writer/prototype/examples/common/ExampleKernelWriter.cpp13
-rw-r--r--compute_kernel_writer/prototype/examples/common/ExampleScopedKernelWriter.cpp1
-rw-r--r--compute_kernel_writer/prototype/examples/writer_helper.cpp31
6 files changed, 48 insertions, 48 deletions
diff --git a/compute_kernel_writer/prototype/examples/add_exp_store.cpp b/compute_kernel_writer/prototype/examples/add_exp_store.cpp
index 6a9884543c..2b640ca01b 100644
--- a/compute_kernel_writer/prototype/examples/add_exp_store.cpp
+++ b/compute_kernel_writer/prototype/examples/add_exp_store.cpp
@@ -32,7 +32,6 @@
#include "common/ExampleComponentArgument.h"
#include "common/ExampleKernelWriter.h"
#include "common/ExampleScopedKernelWriter.h"
-
#include <iostream>
#include <vector>
@@ -78,14 +77,14 @@ void op_binary_elementwise(ExampleScopedKernelWriter writer, std::vector<Example
auto dst = operands.at(2);
// Load the LHS and RHS tile and prepare the tensor sampler.
- if(!lhs->has_tile() && !rhs->has_tile())
+ if (!lhs->has_tile() && !rhs->has_tile())
{
const auto sampler = create_simple_sampler(writer);
writer->op_load_once(lhs, sampler);
writer->op_load_once(rhs, sampler);
}
- else if(lhs->has_tile())
+ else if (lhs->has_tile())
{
const auto &sampler = lhs->tile_sampler();
writer->op_load_once(rhs, sampler);
@@ -101,7 +100,7 @@ void op_binary_elementwise(ExampleScopedKernelWriter writer, std::vector<Example
const auto &sampler = lhs->tile_sampler();
// Prepare the output tile.
- if(!dst->has_tile())
+ if (!dst->has_tile())
{
auto &tile = writer->declare_tile("dst_tile", lhs_tile.tile_info());
dst->init_virtual_tensor(tile, sampler);
@@ -119,7 +118,7 @@ void op_exp(ExampleScopedKernelWriter writer, std::vector<ExampleComponentArgume
auto dst = operands.at(1);
// Load the source tile and prepare the sampler.
- if(!src->has_tile())
+ if (!src->has_tile())
{
const auto sampler = create_simple_sampler(writer);
writer->op_load_once(src, sampler);
@@ -129,7 +128,7 @@ void op_exp(ExampleScopedKernelWriter writer, std::vector<ExampleComponentArgume
const auto &sampler = src->tile_sampler();
// Prepare the output tile.
- if(!dst->has_tile())
+ if (!dst->has_tile())
{
auto &tile = writer->declare_tile("dst_tile", src_tile.tile_info());
dst->init_virtual_tensor(tile, sampler);
@@ -160,34 +159,38 @@ int main()
ExampleScopedKernelWriter writer(&root_writer);
- const TensorInfo src0_info(DataType::Fp32, TensorShape({ 3, 10, 20, 1, 1 }), TensorDataLayout::Nhwc, 0);
- const TensorInfo src1_info(DataType::Fp32, TensorShape({ 3, 10, 20, 1, 1 }), TensorDataLayout::Nhwc, 1);
- const TensorInfo dst_info(DataType::Fp32, TensorShape({ 3, 10, 20, 1, 1 }), TensorDataLayout::Nhwc, 2);
+ const TensorInfo src0_info(DataType::Fp32, TensorShape({3, 10, 20, 1, 1}), TensorDataLayout::Nhwc, 0);
+ const TensorInfo src1_info(DataType::Fp32, TensorShape({3, 10, 20, 1, 1}), TensorDataLayout::Nhwc, 1);
+ const TensorInfo dst_info(DataType::Fp32, TensorShape({3, 10, 20, 1, 1}), TensorDataLayout::Nhwc, 2);
- ExampleComponentArgument src0(writer->declare_tensor_argument("src0", src0_info, TensorStorageType::BufferUint8Ptr));
- ExampleComponentArgument src1(writer->declare_tensor_argument("src1", src1_info, TensorStorageType::BufferUint8Ptr));
+ ExampleComponentArgument src0(
+ writer->declare_tensor_argument("src0", src0_info, TensorStorageType::BufferUint8Ptr));
+ ExampleComponentArgument src1(
+ writer->declare_tensor_argument("src1", src1_info, TensorStorageType::BufferUint8Ptr));
ExampleComponentArgument dst(writer->declare_tensor_argument("dst", dst_info, TensorStorageType::BufferUint8Ptr));
ExampleComponentArgument ans;
- op_binary_elementwise(writer, { &src0, &src1, &ans });
- op_exp(writer, { &ans, &ans });
- op_store(writer, { &ans, &dst });
+ op_binary_elementwise(writer, {&src0, &src1, &ans});
+ op_exp(writer, {&ans, &ans});
+ op_store(writer, {&ans, &dst});
const auto arguments = kernel.arguments();
std::cout << "\n====================\nArguments:\n====================\n";
- for(auto &arg : arguments)
+ for (auto &arg : arguments)
{
- switch(arg.type())
+ switch (arg.type())
{
case ckw::KernelArgument::Type::TensorStorage:
- std::cout << "* Tensor storage: ID = " << arg.id() << ", type = " << std::hex << "0x" << static_cast<uint32_t>(arg.tensor_storage_type()) << std::dec << "\n";
+ std::cout << "* Tensor storage: ID = " << arg.id() << ", type = " << std::hex << "0x"
+ << static_cast<uint32_t>(arg.tensor_storage_type()) << std::dec << "\n";
break;
case ckw::KernelArgument::Type::TensorComponent:
- std::cout << "* Tensor component: ID = " << arg.id() << ", type = " << std::hex << "0x" << static_cast<uint32_t>(arg.tensor_component_type()) << std::dec << "\n";
+ std::cout << "* Tensor component: ID = " << arg.id() << ", type = " << std::hex << "0x"
+ << static_cast<uint32_t>(arg.tensor_component_type()) << std::dec << "\n";
break;
default:
diff --git a/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.cpp b/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.cpp
index 5a2ec526cc..55223dae0e 100644
--- a/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.cpp
+++ b/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.cpp
@@ -23,19 +23,19 @@
*/
#include "ExampleComponentArgument.h"
+
#include "ckw/Error.h"
ExampleComponentArgument::ExampleComponentArgument()
{
}
-ExampleComponentArgument::ExampleComponentArgument(ckw::TensorOperand &tensor)
- : _tensor(&tensor)
+ExampleComponentArgument::ExampleComponentArgument(ckw::TensorOperand &tensor) : _tensor(&tensor)
{
}
-ExampleComponentArgument &
-ExampleComponentArgument::init_virtual_tensor(ckw::TileOperand &tile, const ckw::TensorTileSampler &tile_sampler)
+ExampleComponentArgument &ExampleComponentArgument::init_virtual_tensor(ckw::TileOperand &tile,
+ const ckw::TensorTileSampler &tile_sampler)
{
CKW_ASSERT(_tile == nullptr);
diff --git a/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.h b/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.h
index 9fdc50ba08..0e029b1157 100644
--- a/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.h
+++ b/compute_kernel_writer/prototype/examples/common/ExampleComponentArgument.h
@@ -104,8 +104,8 @@ public:
const ckw::TensorTileSampler &tile_sampler() const;
private:
- ckw::TensorOperand *_tensor{ nullptr };
- ckw::TileOperand *_tile{ nullptr };
+ ckw::TensorOperand *_tensor{nullptr};
+ ckw::TileOperand *_tile{nullptr};
ckw::TensorTileSampler _tile_sampler{};
};
diff --git a/compute_kernel_writer/prototype/examples/common/ExampleKernelWriter.cpp b/compute_kernel_writer/prototype/examples/common/ExampleKernelWriter.cpp
index 6b9f244735..1734ce8823 100644
--- a/compute_kernel_writer/prototype/examples/common/ExampleKernelWriter.cpp
+++ b/compute_kernel_writer/prototype/examples/common/ExampleKernelWriter.cpp
@@ -23,26 +23,27 @@
*/
#include "ExampleKernelWriter.h"
-#include "ExampleComponentArgument.h"
+
#include "ckw/Error.h"
#include "ckw/TileInfo.h"
-ExampleKernelWriter::ExampleKernelWriter(ckw::Kernel &kernel)
- : KernelWriter(kernel)
+#include "ExampleComponentArgument.h"
+
+ExampleKernelWriter::ExampleKernelWriter(ckw::Kernel &kernel) : KernelWriter(kernel)
{
}
void ExampleKernelWriter::op_load_once(ExampleComponentArgument *tensor_or_tile, const ckw::TensorTileSampler &sampler)
{
- if(!tensor_or_tile->has_tile())
+ if (!tensor_or_tile->has_tile())
{
CKW_ASSERT(tensor_or_tile->has_tensor());
auto &tensor = tensor_or_tile->tensor();
const auto tile_name = tensor.name() + "_tile";
- auto &tile = declare_tile(tile_name.c_str(),
- ckw::TileInfo(tensor.data_type(), sampler.height(), sampler.width()));
+ auto &tile =
+ declare_tile(tile_name.c_str(), ckw::TileInfo(tensor.data_type(), sampler.height(), sampler.width()));
op_load(tile, tensor, sampler);
diff --git a/compute_kernel_writer/prototype/examples/common/ExampleScopedKernelWriter.cpp b/compute_kernel_writer/prototype/examples/common/ExampleScopedKernelWriter.cpp
index 7c44fa8749..784d5ffb96 100644
--- a/compute_kernel_writer/prototype/examples/common/ExampleScopedKernelWriter.cpp
+++ b/compute_kernel_writer/prototype/examples/common/ExampleScopedKernelWriter.cpp
@@ -23,6 +23,7 @@
*/
#include "ExampleScopedKernelWriter.h"
+
#include "ExampleKernelWriter.h"
ExampleScopedKernelWriter::ExampleScopedKernelWriter(ExampleKernelWriter *writer)
diff --git a/compute_kernel_writer/prototype/examples/writer_helper.cpp b/compute_kernel_writer/prototype/examples/writer_helper.cpp
index ccef92dcdf..8623afbf50 100644
--- a/compute_kernel_writer/prototype/examples/writer_helper.cpp
+++ b/compute_kernel_writer/prototype/examples/writer_helper.cpp
@@ -23,14 +23,14 @@
*/
#include "ckw/KernelWriter.h"
-#include "../include/ckw/KernelWriterHelper.h"
#include "ckw/TensorTileSampler.h"
+#include "../include/ckw/KernelWriterHelper.h"
#include <iostream>
using namespace ckw;
-TensorTileSampler create_simple_sampler(KernelWriter& writer)
+TensorTileSampler create_simple_sampler(KernelWriter &writer)
{
TensorTileSampler sampler;
@@ -65,11 +65,11 @@ TensorTileSampler create_simple_sampler(KernelWriter& writer)
int main()
{
- Kernel kernel("test", GpuTargetLanguage::OpenCL);
+ Kernel kernel("test", GpuTargetLanguage::OpenCL);
KernelWriterHelper<KernelWriter> writer(kernel);
- const TensorInfo src_info(DataType::Fp32, TensorShape({ 1, 1, 1, 1, 1 }), TensorDataLayout::Nhwc, 0);
- const TensorInfo dst_info(DataType::Fp32, TensorShape({ 1, 1, 1, 1, 1 }), TensorDataLayout::Nhwc, 1);
+ const TensorInfo src_info(DataType::Fp32, TensorShape({1, 1, 1, 1, 1}), TensorDataLayout::Nhwc, 0);
+ const TensorInfo dst_info(DataType::Fp32, TensorShape({1, 1, 1, 1, 1}), TensorDataLayout::Nhwc, 1);
auto &src_tensor = writer.declare_tensor_argument("src", src_info);
auto &dst_tensor = writer.declare_tensor_argument("dst", dst_info);
@@ -77,27 +77,24 @@ int main()
const auto sampler = create_simple_sampler(writer);
auto &src = writer.declare_tile("src_tile", TileInfo(src_tensor.data_type(), sampler.height(), sampler.width()));
- auto &other = writer.declare_tile("other_tile", TileInfo(src_tensor.data_type(), sampler.height(), sampler.width()));
+ auto &other =
+ writer.declare_tile("other_tile", TileInfo(src_tensor.data_type(), sampler.height(), sampler.width()));
auto &dst = writer.declare_tile("dst_tile", TileInfo(src_tensor.data_type(), sampler.height(), sampler.width()));
writer.op_load(src, src_tensor, sampler);
writer.op_load(other, src_tensor, sampler);
writer.op_load(dst, dst_tensor, sampler);
- auto test = dst ^ src ^ other;
+ auto test = dst ^ src ^ other;
auto other_test = logical_and(dst, src, other);
writer.op_assign(dst, logical_and(dst, src, other));
writer.op_assign(dst, test);
writer.op_assign(dst, other_test);
writer.op_assign(dst, operator^(operator^(dst, src), other));
- writer.op_if(exp(src) == dst, [&]{
- writer.op_binary_expression(dst, src, BinaryOp::Add, src);
- }).op_else_if(exp(src) > dst, [&]{
- writer.op_binary_expression(dst, src, BinaryOp::Add, src);
- }).op_else([&] {
- writer.op_assign(dst, src);
- });
+ writer.op_if(exp(src) == dst, [&] { writer.op_binary_expression(dst, src, BinaryOp::Add, src); })
+ .op_else_if(exp(src) > dst, [&] { writer.op_binary_expression(dst, src, BinaryOp::Add, src); })
+ .op_else([&] { writer.op_assign(dst, src); });
writer.op_assign(dst, src + src * src);
writer.op_assign(dst, src * max(src, dst) + src);
@@ -106,13 +103,11 @@ int main()
writer.op_assign(dst, src ^ dst);
writer.op_assign(dst, ~src);
- writer.op_for_loop(dst < src, dst += src, [&]{
- writer.op_assign(dst, src + dst);
- });
+ writer.op_for_loop(dst < src, dst += src, [&] { writer.op_assign(dst, src + dst); });
writer.op_assign(dst += src);
writer.op_assign(dst += exp(src));
std::cout << "======== KERNEL ========" << std::endl;
std::cout << writer.generate_code() << std::endl;
-} \ No newline at end of file
+}