#include #include #include #include #include "utils.hpp" int main() { using InputType = float; const int64_t n = 16; // 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 // Conv param const int64_t strideH = 1; // Height stride const int64_t strideW = 1; // Width stride const int64_t padH = 1; // Height padding const int64_t padW = 1; // Width padding const int64_t dilH = 1; // Height dilation const int64_t dilW = 1; // Width dilation auto buildConvForwardGraph = [=](hipdnnHandle_t handle) { auto graph = std::make_shared(); graph->set_name("conv_forward_graph") .set_io_data_type(hipdnn_frontend::getDataTypeEnumFromType()) .set_intermediate_data_type(hipdnn_frontend::getDataTypeEnumFromType()) .set_compute_data_type(hipdnn_frontend::DataType::FLOAT); auto image = std::make_shared( 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::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({padH, padW}) .set_stride({strideH, strideW}) .set_dilation({dilH, dilW}); auto y = graph->conv_fprop(image, filter, convFpropAttributes); y->set_output(true); // build graph HIPDNN_FE_CHECK(graph->build(handle)); return std::make_tuple(graph, image, filter, 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, input, filter, y] = buildConvForwardGraph(handle); hipdnn_data_sdk::utilities::Tensor inputTensor(input->get_dim(), input->get_stride()); hipdnn_data_sdk::utilities::Tensor filterTensor(filter->get_dim(), filter->get_stride()); hipdnn_data_sdk::utilities::Tensor yTensor(y->get_dim(), y->get_stride()); std::unordered_map variantPack; variantPack[input->get_uid()] = inputTensor.memory().deviceData(); variantPack[filter->get_uid()] = filterTensor.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(workspaceSize)); HIPDNN_FE_CHECK(graph->execute(handle, variantPack, workspace.get())); std::cout << "Convolution forward graph execution complete. \n"; HIPDNN_CHECK(backend->destroy(handle)); return 0; }