-
Notifications
You must be signed in to change notification settings - Fork 251
Expand file tree
/
Copy pathslice.cpp
More file actions
78 lines (58 loc) · 2.69 KB
/
Copy pathslice.cpp
File metadata and controls
78 lines (58 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: MIT
*/
#include <catch2/catch_test_macros.hpp>
#include "../utils/helpers.h"
#include <cudnn_frontend.h>
TEST_CASE("Slice gemm", "[slice][gemm][graph][fusion]") {
namespace fe = cudnn_frontend;
constexpr int B_start = 1;
constexpr int B = 8;
constexpr int B_end = 2;
constexpr int B_actual = B_start + B + B_end;
constexpr int M_start = 3;
constexpr int M = 16;
constexpr int M_end = 4;
constexpr int M_actual = M_start + M + M_end;
constexpr int N = 32;
constexpr int K = 64;
constexpr int a_uid = 1, b_uid = 2, c_uid = 3;
fe::graph::Graph graph{};
graph.set_io_data_type(fe::DataType_t::HALF).set_compute_data_type(fe::DataType_t::FLOAT);
auto A = graph.tensor(fe::graph::Tensor_attributes()
.set_dim({B_actual, M_actual, K})
.set_stride({M_actual * K, K, 1})
.set_uid(a_uid));
auto slice_params = fe::graph::Slice_attributes().set_name("slice").set_slices(
{{B_start, B_start + B}, {M_start, M_start + M}, {0, K}});
auto A_slice = graph.slice(A, slice_params);
A_slice->set_data_type(fe::DataType_t::HALF);
auto B0 = graph.tensor(fe::graph::Tensor_attributes().set_dim({B, K, N}).set_stride({K * N, N, 1}).set_uid(b_uid));
auto C0 = graph.matmul(A_slice, B0, fe::graph::Matmul_attributes().set_name("matmul"));
C0->set_data_type(fe::DataType_t::FLOAT);
auto C =
graph.pointwise(C0, fe::graph::Pointwise_attributes().set_name("relu").set_mode(fe::PointwiseMode_t::RELU_FWD));
C->set_output(true).set_uid(c_uid);
// Create a unique_ptr for the cuDNN handle
auto handle_ptr = create_cudnn_handle();
auto handle = *handle_ptr;
REQUIRE(graph.build(handle, {fe::HeurMode_t::A}).is_good());
std::vector<uint8_t> serialized_data;
REQUIRE(graph.serialize(serialized_data).is_good());
Surface<half> A_gpu(B_actual * M_actual * K);
Surface<half> B_gpu(B * K * N);
Surface<half> C_gpu(B * M * N);
std::unordered_map<int64_t, void *> variant_pack = {
{a_uid, A_gpu.devPtr}, {b_uid, B_gpu.devPtr}, {c_uid, C_gpu.devPtr}};
int64_t workspace_size = 0;
REQUIRE(graph.get_workspace_size(workspace_size).is_good());
Surface<int8_t> workspace(workspace_size);
fe::graph::Graph graph2;
REQUIRE(graph2.deserialize(handle, serialized_data).is_good());
auto result = graph2.execute(handle, variant_pack, workspace.devPtr);
if (!result.is_good()) {
std::cerr << result.get_message();
REQUIRE(false);
}
}