cudnn-frontend icon indicating copy to clipboard operation
cudnn-frontend copied to clipboard

[Question] How to add bias after conv?

Open zhewenhu opened this issue 5 months ago • 4 comments

Hi all, I am building the graph as in the image: Image The document suggests this graph is supported, but I got the seg fault at get_uid when doing graph->execute, could anyone help me to solve the problem?

I basically used the example here, but removed scaling. Here is my code:

graph = std::make_shared<fe::graph::Graph>();
graph->set_io_data_type(fe::DataType_t::FLOAT)
    .set_intermediate_data_type(fe::DataType_t::FLOAT)
    .set_compute_data_type(fe::DataType_t::FLOAT);

X = graph->tensor(fe::graph::Tensor_attributes()
                           .set_name("image")
                           .set_dim({n, c, h, w})
                           .set_stride({c * h * w, 1, c * w, c}));

W = graph->tensor(fe::graph::Tensor_attributes()
                           .set_name("filter")
                           .set_dim({k, c, r, s})
                           .set_stride({c * r * s, 1, r * s, s}));

conv_options =
    fe::graph::Conv_fprop_attributes().set_padding({1, 1}).set_stride({1, 1}).set_dilation({1, 1});
conv_output = graph->conv_fprop(X, W, conv_options);

B = graph->tensor(
            fe::graph::Tensor_attributes().set_name("bias").set_dim({1, k, 1, 1}).set_stride({k, 1, 1, 1}));
bias_options = fe::graph::Pointwise_attributes().set_mode(fe::PointwiseMode_t::ADD);
bias_output  = graph->pointwise(conv_output, B, bias_options);

gelu_options = fe::graph::Pointwise_attributes().set_mode(fe::PointwiseMode_t::GELU_FWD);
Y            = graph->pointwise(bias_output, gelu_options);
Y->set_output(true);

checkCudnnFeErr(graph1->validate(), "Graph validation failed");
checkCudnnFeErr(graph1->build_operation_graph(handle), "Building operation graph failed");
checkCudnnFeErr(graph1->create_execution_plans({fe::HeurMode_t::A}), "Creating execution plans failed");
checkCudnnFeErr(graph1->check_support(handle), "Checking graph support failed");
checkCudnnFeErr(graph1->build_plans(handle), "Building plans failed");

// initialize input, filter and output vector

std::unordered_map<std::shared_ptr<fe::graph::Tensor_attributes>, void*> variant_pack_1 = {
        {X, input}, {W, weight_devPtr}, {B, b_devPtr}, {Y, output_devPtr}};

zhewenhu avatar Sep 10 '24 23:09 zhewenhu