Commit ca34d4d2 authored by yanjl1's avatar yanjl1
Browse files

Initial

parents
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include <iostream>
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
#include "../utils.hpp"
int main()
{
using InputType = float;
const int64_t n = 1;
const int64_t c = 4;
const int64_t h = 32;
const int64_t w = 32;
auto buildScaleBiasGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("scale_bias_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT);
auto x = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("x")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto scale = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("scale")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto mulAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("mul_node")
.set_mode(hipdnn_frontend::PointwiseMode::MUL);
auto mulOut = graph->pointwise(x, scale, mulAttrs);
auto addAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode::ADD);
auto y = graph->pointwise(mulOut, bias, addAttrs);
y->set_output(true);
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, x, scale, bias, y);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, x, scale, bias, y] = buildScaleBiasGraph(handle);
hipdnn_data_sdk::utilities::Tensor<InputType> xTensor(x->get_dim(), x->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> scaleTensor(scale->get_dim(),
scale->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> yTensor(y->get_dim(), y->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[x->get_uid()] = xTensor.memory().deviceData();
variantPack[scale->get_uid()] = scaleTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[y->get_uid()] = yTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "ScaleBias graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include <iostream>
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
#include "../utils.hpp"
int main()
{
using InputType = float;
const int64_t n = 4;
const int64_t c = 64;
const int64_t h = 16;
const int64_t w = 16;
const int64_t k = 32;
const int64_t r = 3;
const int64_t s = 3;
auto buildScaleBiasReluConvGenstatsGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("scale_bias_relu_conv_genstats_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT);
auto x = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("x")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto scale = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("scale")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto mulAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("mul_node")
.set_mode(hipdnn_frontend::PointwiseMode::MUL);
auto mulOut = graph->pointwise(x, scale, mulAttrs);
auto addAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode::ADD);
auto addOut = graph->pointwise(mulOut, bias, addAttrs);
auto reluAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("relu_fwd_node")
.set_mode(hipdnn_frontend::PointwiseMode::RELU_FWD);
auto reluOut = graph->pointwise(addOut, reluAttrs);
auto convAttrs = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding({1, 1})
.set_stride({1, 1})
.set_dilation({1, 1});
auto y = graph->conv_fprop(reluOut, filter, convAttrs);
auto genstatsAttrs = hipdnn_frontend::graph::GenstatsAttributes().set_name("genstats_node");
auto [sum, sqSum] = graph->genstats(y, genstatsAttrs);
y->set_output(true);
sum->set_output(true);
sqSum->set_output(true);
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, x, scale, bias, filter, y, sum, sqSum);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, x, scale, bias, filter, y, sum, sqSum]
= buildScaleBiasReluConvGenstatsGraph(handle);
hipdnn_data_sdk::utilities::Tensor<InputType> xTensor(x->get_dim(), x->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> scaleTensor(scale->get_dim(),
scale->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> filterTensor(filter->get_dim(),
filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> yTensor(y->get_dim(), y->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> sumTensor(sum->get_dim(), sum->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> sqSumTensor(sqSum->get_dim(),
sqSum->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[x->get_uid()] = xTensor.memory().deviceData();
variantPack[scale->get_uid()] = scaleTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[filter->get_uid()] = filterTensor.memory().deviceData();
variantPack[y->get_uid()] = yTensor.memory().deviceData();
variantPack[sum->get_uid()] = sumTensor.memory().deviceData();
variantPack[sqSum->get_uid()] = sqSumTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "ScaleBiasReluConvGenstats graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include <iostream>
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
#include "../utils.hpp"
int main()
{
using InputType = float;
const int64_t n = 1;
const int64_t c = 32;
const int64_t h = 128;
const int64_t w = 128;
const int64_t k = 32;
auto buildScaleBiasReluConvwrwGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("scale_bias_relu_convwrw_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT);
auto x = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("x")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto scale = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("scale")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto dy = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("dy")
.set_dim({n, k, h, w})
.set_stride({k * h * w, 1, k * w, k}));
auto mulAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("mul_node")
.set_mode(hipdnn_frontend::PointwiseMode::MUL);
auto mulOut = graph->pointwise(x, scale, mulAttrs);
auto addAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode::ADD);
auto addOut = graph->pointwise(mulOut, bias, addAttrs);
auto reluAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("relu_fwd_node")
.set_mode(hipdnn_frontend::PointwiseMode::RELU_FWD);
auto reluOut = graph->pointwise(addOut, reluAttrs);
auto convAttrs = hipdnn_frontend::graph::ConvWgradAttributes()
.set_name("conv_wgrad_node")
.set_padding({1, 1})
.set_stride({1, 1})
.set_dilation({1, 1});
auto dw = graph->conv_wgrad(dy, reluOut, convAttrs);
dw->set_output(true);
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, x, scale, bias, dy, dw);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, x, scale, bias, dy, dw] = buildScaleBiasReluConvwrwGraph(handle);
hipdnn_data_sdk::utilities::Tensor<InputType> xTensor(x->get_dim(), x->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> scaleTensor(scale->get_dim(),
scale->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> dyTensor(dy->get_dim(), dy->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> dwTensor(dw->get_dim(), dw->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[x->get_uid()] = xTensor.memory().deviceData();
variantPack[scale->get_uid()] = scaleTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[dy->get_uid()] = dyTensor.memory().deviceData();
variantPack[dw->get_uid()] = dwTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "ScaleBiasReluConvwrw graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include <iostream>
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
#include "../utils.hpp"
int main()
{
using InputType = float;
const int64_t n = 4;
const int64_t c = 64;
const int64_t h = 16;
const int64_t w = 16;
const int64_t k = 32;
const int64_t r = 3;
const int64_t s = 3;
auto buildSubMulMulAddConvbwdRelubwdBnwrwGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("sub_mul_mul_add_convbwd_relubwd_bnwrw_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT);
auto xBn = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("x_bn")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto meanBn = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("mean_bn")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto invStdBn = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("invstd_bn")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto scaleBn = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("scale_bn")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto biasBn = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias_bn")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto dy = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("dy")
.set_dim({n, k, h, w})
.set_stride({k * h * w, 1, k * w, k}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto subAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("sub_node")
.set_mode(hipdnn_frontend::PointwiseMode::SUB);
auto subOut = graph->pointwise(xBn, meanBn, subAttrs);
auto mulAttrs0 = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("mul0_node")
.set_mode(hipdnn_frontend::PointwiseMode::MUL);
auto mulOut0 = graph->pointwise(subOut, invStdBn, mulAttrs0);
auto mulAttrs1 = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("mul1_node")
.set_mode(hipdnn_frontend::PointwiseMode::MUL);
auto mulOut1 = graph->pointwise(mulOut0, scaleBn, mulAttrs1);
auto addAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode::ADD);
auto addOut = graph->pointwise(mulOut1, biasBn, addAttrs);
auto convAttrs = hipdnn_frontend::graph::ConvDgradAttributes()
.set_name("conv_dgrad_node")
.set_padding({1, 1})
.set_stride({1, 1})
.set_dilation({1, 1});
auto dx = graph->conv_dgrad(dy, filter, convAttrs);
auto reluBwdAttrs = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("relu_bwd_node")
.set_mode(hipdnn_frontend::PointwiseMode::RELU_BWD);
auto dRelu = graph->pointwise(dx, addOut, reluBwdAttrs);
dRelu->set_output(true);
auto bnWgradAttrs = hipdnn_frontend::graph::BatchnormBackwardWeightAttributes().set_name(
"bn_backward_weight_node");
auto [dscale, dbias, eqScaleDy, eqScaleX, eqBias]
= graph->dbn_weight(dRelu, xBn, meanBn, invStdBn, scaleBn, bnWgradAttrs);
dscale->set_output(true);
dbias->set_output(true);
eqScaleDy->set_output(true);
eqScaleX->set_output(true);
eqBias->set_output(true);
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph,
xBn,
meanBn,
invStdBn,
scaleBn,
biasBn,
dy,
filter,
dRelu,
dscale,
dbias,
eqScaleDy,
eqScaleX,
eqBias);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph,
xBn,
meanBn,
invStdBn,
scaleBn,
biasBn,
dy,
filter,
dRelu,
dscale,
dbias,
eqScaleDy,
eqScaleX,
eqBias]
= buildSubMulMulAddConvbwdRelubwdBnwrwGraph(handle);
hipdnn_data_sdk::utilities::Tensor<InputType> xBnTensor(xBn->get_dim(), xBn->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> meanBnTensor(meanBn->get_dim(),
meanBn->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> invStdBnTensor(invStdBn->get_dim(),
invStdBn->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> scaleBnTensor(scaleBn->get_dim(),
scaleBn->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasBnTensor(biasBn->get_dim(),
biasBn->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> dyTensor(dy->get_dim(), dy->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> filterTensor(filter->get_dim(),
filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> dReluTensor(dRelu->get_dim(),
dRelu->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> dscaleTensor(dscale->get_dim(),
dscale->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> dbiasTensor(dbias->get_dim(),
dbias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> eqScaleDyTensor(eqScaleDy->get_dim(),
eqScaleDy->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> eqScaleXTensor(eqScaleX->get_dim(),
eqScaleX->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> eqBiasTensor(eqBias->get_dim(),
eqBias->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[xBn->get_uid()] = xBnTensor.memory().deviceData();
variantPack[meanBn->get_uid()] = meanBnTensor.memory().deviceData();
variantPack[invStdBn->get_uid()] = invStdBnTensor.memory().deviceData();
variantPack[scaleBn->get_uid()] = scaleBnTensor.memory().deviceData();
variantPack[biasBn->get_uid()] = biasBnTensor.memory().deviceData();
variantPack[dy->get_uid()] = dyTensor.memory().deviceData();
variantPack[filter->get_uid()] = filterTensor.memory().deviceData();
variantPack[dRelu->get_uid()] = dReluTensor.memory().deviceData();
variantPack[dscale->get_uid()] = dscaleTensor.memory().deviceData();
variantPack[dbias->get_uid()] = dbiasTensor.memory().deviceData();
variantPack[eqScaleDy->get_uid()] = eqScaleDyTensor.memory().deviceData();
variantPack[eqScaleX->get_uid()] = eqScaleXTensor.memory().deviceData();
variantPack[eqBias->get_uid()] = eqBiasTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "SubMulMulAddConvbwdRelubwdBnwrw graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <cstdint>
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 64; // Number of channels
const int64_t h = 540; // Height
const int64_t w = 960; // Width
// Filter
const int64_t k = 256; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
// blockSize
const int64_t blockSize = 2;
// Conv param
const std::vector<int64_t> strides = {1, 1};
const std::vector<int64_t> padding = {1, 1};
const std::vector<int64_t> dilation = {1, 1};
const int64_t outH = ((h + 2 * padding[0] - (dilation[0] * (r - 1) + 1)) / strides[0]) + 1;
const int64_t outW = ((w + 2 * padding[1] - (dilation[1] * (s - 1) + 1)) / strides[1]) + 1;
auto buildConvDepthToSpaceGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_depth_to_space_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("image")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding(padding)
.set_stride(strides)
.set_dilation(dilation);
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create add
auto add = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("add")
.set_dim({n, k, outH, outW})
.set_stride({k * outH * outW, 1, k * outW, k}));
auto addAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto addOutput = graph->pointwise(biasOutput, add, addAttributes);
// create reshape
auto firstReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("first_reshape_node")
.set_dim({n, k / (blockSize * blockSize), blockSize, blockSize, outH, outW});
auto firstReshapeOutput = graph->reshape(addOutput, firstReshapeAttributes);
// create transpose
auto transposeAttributes = hipdnn_frontend::graph::TransposeAttributes()
.set_name("transpose_node")
.set_permutation({0, 1, 4, 2, 5, 3}); // CRD
auto transposeOutput = graph->transpose(firstReshapeOutput, transposeAttributes);
// create reshape
auto secondReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("second_reshape_node")
.set_dim({n, k / (blockSize * blockSize), outH * blockSize, outW * blockSize})
.set_stride(
{k * outH * outW, 1, k / blockSize * outW, k / (blockSize * blockSize)});
auto secondReshapeOutput = graph->reshape(transposeOutput, secondReshapeAttributes);
secondReshapeOutput->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, add, secondReshapeOutput);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, add, output] = buildConvDepthToSpaceGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> addTensor(add->get_dim(), add->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[add->get_uid()] = addTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_depth_to_space_pointwise graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <cstdint>
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 8; // Number of channels
const int64_t h = 128; // Height
const int64_t w = 128; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
// blockSize
const int64_t blockSize = 2;
// Conv param
const std::vector<int64_t> strides = {1, 1};
const std::vector<int64_t> padding = {1, 1};
const std::vector<int64_t> dilation = {1, 1};
const int64_t outH = ((h + 2 * padding[0] - (dilation[0] * (r - 1) + 1)) / strides[0]) + 1;
const int64_t outW = ((w + 2 * padding[1] - (dilation[1] * (s - 1) + 1)) / strides[1]) + 1;
auto buildConvDepthToSpaceGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_depth_to_space_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("image")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding(padding)
.set_stride(strides)
.set_dilation(dilation);
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create reshape
auto firstReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("first_reshape_node")
.set_dim({n, k / (blockSize * blockSize), blockSize, blockSize, outH, outW});
auto firstReshapeOutput = graph->reshape(biasOutput, firstReshapeAttributes);
// create transpose
auto transposeAttributes = hipdnn_frontend::graph::TransposeAttributes()
.set_name("transpose_node")
.set_permutation({0, 1, 4, 2, 5, 3}); // CRD
auto transposeOutput = graph->transpose(firstReshapeOutput, transposeAttributes);
// create reshape
auto secondReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("second_reshape_node")
.set_dim({n, k / (blockSize * blockSize), outH * blockSize, outW * blockSize})
.set_stride(
{k * outH * outW, 1, k / blockSize * outW, k / (blockSize * blockSize)});
auto secondReshapeOutput = graph->reshape(transposeOutput, secondReshapeAttributes);
secondReshapeOutput->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, secondReshapeOutput);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, output] = buildConvDepthToSpaceGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_depth_to_space_pointwise graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <cstdint>
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 8; // Number of channels
const int64_t h = 128; // Height
const int64_t w = 128; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
// blockSize
const int64_t blockSize = 2;
// Conv param
const std::vector<int64_t> strides = {1, 1};
const std::vector<int64_t> padding = {1, 1};
const std::vector<int64_t> dilation = {1, 1};
const int64_t outH = ((h + 2 * padding[0] - (dilation[0] * (r - 1) + 1)) / strides[0]) + 1;
const int64_t outW = ((w + 2 * padding[1] - (dilation[1] * (s - 1) + 1)) / strides[1]) + 1;
auto buildConvDepthToSpaceGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_depth_to_space_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("image")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding(padding)
.set_stride(strides)
.set_dilation(dilation);
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create reshape
auto firstReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("first_reshape_node")
.set_dim({n, k / (blockSize * blockSize), blockSize, blockSize, outH, outW});
auto firstReshapeOutput = graph->reshape(biasOutput, firstReshapeAttributes);
// create transpose
auto transposeAttributes = hipdnn_frontend::graph::TransposeAttributes()
.set_name("transpose_node")
.set_permutation({0, 1, 4, 2, 5, 3}); // CRD
auto transposeOutput = graph->transpose(firstReshapeOutput, transposeAttributes);
// create reshape
auto secondReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("second_reshape_node")
.set_dim({n, k / (blockSize * blockSize), outH * blockSize, outW * blockSize})
.set_stride(
{k * outH * outW, 1, k / blockSize * outW, k / (blockSize * blockSize)});
auto secondReshapeOutput = graph->reshape(transposeOutput, secondReshapeAttributes);
// create add
auto add = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("add")
.set_dim({n, k / (blockSize * blockSize), h * blockSize, w * blockSize})
.set_stride({k * h * w,
1,
k / (blockSize * blockSize) * w * blockSize,
k / (blockSize * blockSize)}));
auto addAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto addOutput = graph->pointwise(secondReshapeOutput, add, addAttributes);
addOutput->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, add, addOutput);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, add, output] = buildConvDepthToSpaceGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> addTensor(add->get_dim(), add->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[add->get_uid()] = addTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_depth_to_space_pointwise graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <cstdint>
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 8; // Number of channels
const int64_t h = 128; // Height
const int64_t w = 128; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
// blockSize
const int64_t blockSize = 2;
// Conv param
const std::vector<int64_t> strides = {1, 1};
const std::vector<int64_t> padding = {1, 1};
const std::vector<int64_t> dilation = {1, 1};
const int64_t outH = ((h + 2 * padding[0] - (dilation[0] * (r - 1) + 1)) / strides[0]) + 1;
const int64_t outW = ((w + 2 * padding[1] - (dilation[1] * (s - 1) + 1)) / strides[1]) + 1;
auto buildConvDepthToSpaceGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_depth_to_space_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("image")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding(padding)
.set_stride(strides)
.set_dilation(dilation);
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create reshape
auto firstReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("first_reshape_node")
.set_dim({n, k / (blockSize * blockSize), blockSize, blockSize, outH, outW});
auto firstReshapeOutput = graph->reshape(biasOutput, firstReshapeAttributes);
// create transpose
auto transposeAttributes = hipdnn_frontend::graph::TransposeAttributes()
.set_name("transpose_node")
.set_permutation({0, 1, 4, 2, 5, 3}); // CRD
auto transposeOutput = graph->transpose(firstReshapeOutput, transposeAttributes);
// create reshape
auto secondReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("second_reshape_node")
.set_dim({n, k / (blockSize * blockSize), outH * blockSize, outW * blockSize})
.set_stride(
{k * outH * outW, 1, k / blockSize * outW, k / (blockSize * blockSize)});
auto secondReshapeOutput = graph->reshape(transposeOutput, secondReshapeAttributes);
// creater relu
auto reluAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("relu_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::RELU_FWD)
.set_relu_upper_clip(0.1f);
auto reluOutput = graph->pointwise(secondReshapeOutput, reluAttributes);
reluOutput->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, reluOutput);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, output] = buildConvDepthToSpaceGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_depth_to_space_pointwise graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <cstdint>
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 8; // Number of channels
const int64_t h = 128; // Height
const int64_t w = 128; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
// blockSize
const int64_t blockSize = 2;
// Conv param
const std::vector<int64_t> strides = {1, 1};
const std::vector<int64_t> padding = {1, 1};
const std::vector<int64_t> dilation = {1, 1};
const int64_t outH = ((h + 2 * padding[0] - (dilation[0] * (r - 1) + 1)) / strides[0]) + 1;
const int64_t outW = ((w + 2 * padding[1] - (dilation[1] * (s - 1) + 1)) / strides[1]) + 1;
auto buildConvDepthToSpaceGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_depth_to_space_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("image")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding(padding)
.set_stride(strides)
.set_dilation(dilation);
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create reshape
auto firstReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("first_reshape_node")
.set_dim({n, k / (blockSize * blockSize), blockSize, blockSize, outH, outW});
auto firstReshapeOutput = graph->reshape(biasOutput, firstReshapeAttributes);
// create transpose
auto transposeAttributes = hipdnn_frontend::graph::TransposeAttributes()
.set_name("transpose_node")
.set_permutation({0, 1, 4, 2, 5, 3}); // CRD
auto transposeOutput = graph->transpose(firstReshapeOutput, transposeAttributes);
// create reshape
auto secondReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("second_reshape_node")
.set_dim({n, k / (blockSize * blockSize), outH * blockSize, outW * blockSize})
.set_stride(
{k * outH * outW, 1, k / blockSize * outW, k / (blockSize * blockSize)});
auto secondReshapeOutput = graph->reshape(transposeOutput, secondReshapeAttributes);
// create clipped relu
auto reluAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("relu_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::RELU_FWD)
.set_relu_upper_clip(0.1f);
auto reluOutput = graph->pointwise(secondReshapeOutput, reluAttributes);
// create bias
auto add = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("add")
.set_dim({n, k / (blockSize * blockSize), h * blockSize, w * blockSize})
.set_stride({k * h * w,
1,
k / (blockSize * blockSize) * w * blockSize,
k / (blockSize * blockSize)}));
auto addAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto addOutput = graph->pointwise(reluOutput, add, addAttributes);
addOutput->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, add, addOutput);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, add, output] = buildConvDepthToSpaceGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> addTensor(add->get_dim(), add->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[add->get_uid()] = addTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_depth_to_space_pointwise graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <cstdint>
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 8; // Number of channels
const int64_t h = 128; // Height
const int64_t w = 128; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
// blockSize
const int64_t blockSize = 2;
// Conv param
const std::vector<int64_t> strides = {1, 1};
const std::vector<int64_t> padding = {1, 1};
const std::vector<int64_t> dilation = {1, 1};
const int64_t outH = ((h + 2 * padding[0] - (dilation[0] * (r - 1) + 1)) / strides[0]) + 1;
const int64_t outW = ((w + 2 * padding[1] - (dilation[1] * (s - 1) + 1)) / strides[1]) + 1;
auto buildConvDepthToSpaceGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_depth_to_space_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("image")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding(padding)
.set_stride(strides)
.set_dilation(dilation);
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create reshape
auto firstReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("first_reshape_node")
.set_dim({n, k / (blockSize * blockSize), blockSize, blockSize, outH, outW});
auto firstReshapeOutput = graph->reshape(convOutput, firstReshapeAttributes);
// create transpose
auto transposeAttributes = hipdnn_frontend::graph::TransposeAttributes()
.set_name("transpose_node")
.set_permutation({0, 1, 4, 2, 5, 3}); // CRD
auto transposeOutput = graph->transpose(firstReshapeOutput, transposeAttributes);
// create reshape
auto secondReshapeAttributes
= hipdnn_frontend::graph::ReshapeAttributes()
.set_name("second_reshape_node")
.set_dim({n, k / (blockSize * blockSize), outH * blockSize, outW * blockSize})
.set_stride(
{k * outH * outW, 1, k / blockSize * outW, k / (blockSize * blockSize)});
auto output = graph->reshape(transposeOutput, secondReshapeAttributes);
output->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, output] = buildConvDepthToSpaceGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_depth_to_space graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 16; // Number of channels
const int64_t h = 16; // Height
const int64_t w = 16; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
auto buildConvBiasGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_bias_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("input")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding({0, 0})
.set_stride({1, 1})
.set_dilation({1, 1});
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto output = graph->pointwise(convOutput, bias, biasAttributes);
output->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, output] = buildConvBiasGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_bias graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 16; // Number of channels
const int64_t h = 16; // Height
const int64_t w = 16; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
auto buildConvBiasAddGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_bias_add_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("input")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding({0, 0})
.set_stride({1, 1})
.set_dilation({1, 1});
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create add
auto add = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("add")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto addAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto output = graph->pointwise(biasOutput, add, addAttributes);
output->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, add, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, add, output] = buildConvBiasAddGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> addTensor(add->get_dim(), add->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[add->get_uid()] = addTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_bias_add graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 16; // Number of channels
const int64_t h = 16; // Height
const int64_t w = 16; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
auto buildConvBiasAddReluGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_bias_add_relu_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("input")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding({0, 0})
.set_stride({1, 1})
.set_dilation({1, 1});
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create add
auto add = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("add")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto addAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto addOutput = graph->pointwise(biasOutput, add, addAttributes);
// create relu
auto reluAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("relu_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::RELU_FWD);
auto output = graph->pointwise(addOutput, reluAttributes);
output->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, add, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, add, output] = buildConvBiasAddReluGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> addTensor(add->get_dim(), add->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[add->get_uid()] = addTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_bias_add_relu graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 16; // Number of channels
const int64_t h = 16; // Height
const int64_t w = 16; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
auto buildConvBiasPreluGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_bias_prelu_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("input")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding({0, 0})
.set_stride({1, 1})
.set_dilation({1, 1});
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create prelu
auto preluAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("prelu_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::PRELU_FWD)
.set_relu_lower_clip_slope(0.01f);
auto output = graph->pointwise(biasOutput, preluAttributes);
output->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, output] = buildConvBiasPreluGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_bias_prelu graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 16; // Number of channels
const int64_t h = 16; // Height
const int64_t w = 16; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
auto buildConvBiasPreluAddGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_bias_prelu_add_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("input")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding({0, 0})
.set_stride({1, 1})
.set_dilation({1, 1});
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create prelu
auto preluAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("prelu_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::PRELU_FWD)
.set_relu_lower_clip_slope(0.01f);
auto preluOutput = graph->pointwise(biasOutput, preluAttributes);
// create add
auto add = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("add")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto addAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto output = graph->pointwise(preluOutput, add, addAttributes);
output->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, add, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, add, output] = buildConvBiasPreluAddGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> addTensor(add->get_dim(), add->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[add->get_uid()] = addTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_bias_prelu_add graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 16; // Number of channels
const int64_t h = 16; // Height
const int64_t w = 16; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
auto buildConvBiasReluGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("ConvBiasReluGraph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("input")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding({0, 0})
.set_stride({1, 1})
.set_dilation({1, 1});
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create relu
auto reluAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("relu_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::RELU_FWD);
auto output = graph->pointwise(biasOutput, reluAttributes);
output->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, output] = buildConvBiasReluGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_bias_relu graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 16; // Number of channels
const int64_t h = 16; // Height
const int64_t w = 16; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
auto buildConvBiasSwishGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_bias_swish_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("input")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding({0, 0})
.set_stride({1, 1})
.set_dilation({1, 1});
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create swish
auto swishAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("swish_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::SWISH_FWD);
auto output = graph->pointwise(biasOutput, swishAttributes);
output->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, output] = buildConvBiasSwishGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_bias_swish graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 16; // Number of channels
const int64_t h = 16; // Height
const int64_t w = 16; // Width
// Filter
const int64_t k = 16; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
auto buildConvBiasSwishAddGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("conv_bias_swish_add_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("input")
.set_dim({n, c, h, w})
.set_stride({c * h * w, 1, c * w, c}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding({0, 0})
.set_stride({1, 1})
.set_dilation({1, 1});
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create swish
auto swishAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("swish_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::SWISH_FWD);
auto swishOutput = graph->pointwise(biasOutput, swishAttributes);
// create add
auto add = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("add")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto addAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("add_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto output = graph->pointwise(swishOutput, add, addAttributes);
output->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, add, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, add, output] = buildConvBiasSwishAddGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> addTensor(add->get_dim(), add->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[add->get_uid()] = addTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolution_bias_swish_add graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 1; // Batch size
// Input
const int64_t c = 32; // Number of channels
const int64_t outH = 270; // Height
const int64_t outW = 480; // Width
// Filter
const int64_t k = 32; // Number of filters
const int64_t r = 3; // Height
const int64_t s = 3; // Width
// Conv param
const int64_t strideH = 1; // Height stride
const int64_t strideW = 1; // Width stride
const int64_t padH = 0; // Height padding
const int64_t padW = 0; // Width padding
const int64_t dilH = 1; // Height dilation
const int64_t dilW = 1; // Width dilation
const int64_t outputPadH = 0; // Output height padding
const int64_t outputPadW = 0; // Output width padding
auto buildConvbwdBiasReluGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("convbwd_bias_relu_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto loss = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("loss")
.set_dim({n, k, outH, outW})
.set_stride({k * outH * outW, 1, k * outW, k}));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, 1, c * s, c}));
auto convDgradAttributes = hipdnn_frontend::graph::ConvDgradAttributes()
.set_name("conv_backward_node")
.set_padding({padH, padW})
.set_stride({strideH, strideW})
.set_dilation({dilH, dilW})
.set_output_padding({outputPadH, outputPadW});
auto convOutput = graph->conv_dgrad(loss, filter, convDgradAttributes);
// create bias
auto biasIn = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias_in")
.set_dim({1, c, 1, 1})
.set_stride({c, 1, c, c}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, biasIn, biasAttributes);
// create relu
auto reluAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("relu_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::RELU_FWD);
auto output = graph->pointwise(biasOutput, reluAttributes);
output->set_output(true);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, loss, filter, biasIn, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, loss, filter, bias, output] = buildConvbwdBiasReluGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> lossTensor(loss->get_dim(), loss->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[loss->get_uid()] = lossTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "Convolutionbwd_bias_relu graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
#include <iostream>
#include "utils.hpp"
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
#include <hipdnn_data_sdk/utilities/Workspace.hpp>
#include <hipdnn_frontend.hpp>
int main()
{
using InputType = hipdnn_data_sdk::types::half;
const int64_t n = 2; // Batch size
// Input
const int64_t c = 32; // Number of channels
const int64_t h = 16; // Height
const int64_t w = 8; // Width
// Filter
const int64_t k = 128; // Number of filters
const int64_t r = 1; // Height
const int64_t s = 1; // Width
// Conv param
const std::vector<int64_t> strides = {1, 1};
const std::vector<int64_t> padding = {0, 0};
const std::vector<int64_t> dilation = {1, 1};
const int64_t vectorCount = 16;
auto buildConvBiasReluGraph = [=](hipdnnHandle_t handle) {
auto graph = std::make_shared<hipdnn_frontend::graph::Graph>();
graph->set_name("fp16_conv_bias_relu_graph")
.set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType<InputType>())
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT); //
// create conv
auto input = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("input")
.set_dim({n, c, h, w})
.set_stride({c * h * w, h * w, w, 1})
.set_vector_count(vectorCount));
auto filter = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("filter")
.set_dim({k, c, r, s})
.set_stride({c * r * s, r * s, s, 1})
.set_vector_count(vectorCount));
auto convFpropAttributes = hipdnn_frontend::graph::ConvFpropAttributes()
.set_name("conv_fprop_node")
.set_padding(padding)
.set_stride(strides)
.set_dilation(dilation);
auto convOutput = graph->conv_fprop(input, filter, convFpropAttributes);
// create bias
auto bias = std::make_shared<hipdnn_frontend::graph::TensorAttributes>(
hipdnn_frontend::graph::Tensor_attributes()
.set_name("bias")
.set_dim({1, k, 1, 1})
.set_stride({k, 1, k, k}));
auto biasAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("bias_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::ADD);
auto biasOutput = graph->pointwise(convOutput, bias, biasAttributes);
// create relu
auto reluAttributes = hipdnn_frontend::graph::PointwiseAttributes()
.set_name("relu_node")
.set_mode(hipdnn_frontend::PointwiseMode_t::RELU_FWD);
auto output = graph->pointwise(biasOutput, reluAttributes);
output->set_output(true).set_vector_count(vectorCount);
// build graph
HIPDNN_FE_CHECK(graph->build(handle));
return std::make_tuple(graph, input, filter, bias, output);
};
auto backend = hipdnn_frontend::detail::hipdnnBackend();
if(!backend)
{
std::cout << "Creat backend failed. \n";
return 1;
}
hipdnnHandle_t handle;
HIPDNN_CHECK(backend->create(&handle));
auto [graph, input, filter, bias, output] = buildConvBiasReluGraph(handle);
// Allocate DCU memory
hipdnn_data_sdk::utilities::Tensor<InputType> inputTensor(input->get_dim(),
input->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> wTensor(filter->get_dim(), filter->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> biasTensor(bias->get_dim(), bias->get_stride());
hipdnn_data_sdk::utilities::Tensor<InputType> outTensor(output->get_dim(),
output->get_stride());
std::unordered_map<int64_t, void*> variantPack;
variantPack[input->get_uid()] = inputTensor.memory().deviceData();
variantPack[filter->get_uid()] = wTensor.memory().deviceData();
variantPack[bias->get_uid()] = biasTensor.memory().deviceData();
variantPack[output->get_uid()] = outTensor.memory().deviceData();
int64_t workspaceSize = 0;
HIPDNN_FE_CHECK(graph->get_workspace_size(workspaceSize));
const hipdnn_data_sdk::utilities::Workspace workspace(static_cast<size_t>(workspaceSize));
HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get()));
std::cout << "fp16_convolution_bias_relu graph execution complete. \n";
HIPDNN_CHECK(backend->destroy(handle));
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment