Skip to content

Commit 2ee03b6

Browse files
committed
graph: interface: fpmath: construct fpmath_t explicitly
1 parent 3347055 commit 2ee03b6

File tree

6 files changed

+89
-84
lines changed

6 files changed

+89
-84
lines changed

src/graph/interface/graph_attr.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2024 Intel Corporation
2+
* Copyright 2024-2025 Intel Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,16 +24,16 @@ namespace impl {
2424
namespace graph {
2525

2626
struct fpmath_t {
27+
fpmath_t() = default;
2728

28-
fpmath_t(dnnl_fpmath_mode_t mode = fpmath_mode::strict,
29-
bool apply_to_int = false)
29+
fpmath_t(fpmath_mode_t mode, bool apply_to_int)
3030
: mode_(mode), apply_to_int_(apply_to_int) {}
3131

3232
bool operator==(const fpmath_t &rhs) const {
3333
return mode_ == rhs.mode_ && apply_to_int_ == rhs.apply_to_int_;
3434
}
3535

36-
graph::fpmath_mode_t mode_;
36+
fpmath_mode_t mode_ = fpmath_mode::strict;
3737
bool apply_to_int_ = false;
3838
};
3939

tests/gtests/graph/unit/backend/dnnl/test_compiled_partition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ TEST(test_compiled_partition, GetAndInfoMethod) {
309309
graph::dnnl_impl::dnnl_compiled_partition_impl_t>(
310310
engine, inputs, outputs, kernel);
311311
graph::partition_t par;
312+
const graph::fpmath_t fpm {graph::fpmath_mode::strict, false};
312313
auto par_impl = std::make_shared<graph::dnnl_impl::dnnl_partition_impl_t>(
313-
engine.kind(), graph::fpmath_mode::strict,
314-
graph::partition_kind_t::undef);
314+
engine.kind(), fpm, graph::partition_kind_t::undef);
315315
par.init(par_impl);
316316
graph::compiled_partition_t cp(par);
317317
cp.init(cp_impl);

tests/gtests/graph/unit/backend/dnnl/test_layout_propagator_cpu.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2022-2024 Intel Corporation
2+
* Copyright 2022-2025 Intel Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,9 +45,10 @@ TEST(test_layout_propagator, LayoutPropagatorForPermute) {
4545
dnnl::engine p_engine = dnnl_impl::make_dnnl_engine(eng);
4646
dnnl_impl::fusion_info_mgr_t mgr;
4747
dnnl_impl::pd_cache_t pd_cache;
48+
const graph::fpmath_t fpm {graph::fpmath_mode::any, false};
4849
auto sg = std::make_shared<dnnl_impl::subgraph_t>(
49-
std::vector<std::shared_ptr<graph::op_t>> {op}, p_engine,
50-
graph::fpmath_mode::any, false, false);
50+
std::vector<std::shared_ptr<graph::op_t>> {op}, p_engine, fpm,
51+
false, false);
5152
dnnl_impl::subgraph_rewriter_t rewriter {sg};
5253
ASSERT_EQ(dnnl_impl::layout_propagator_for_permute(
5354
op, p_engine, mgr, pd_cache, rewriter),
@@ -69,9 +70,10 @@ TEST(test_layout_propagator, LayoutPropagatorForReorder) {
6970
dnnl::engine p_engine = dnnl_impl::make_dnnl_engine(eng);
7071
dnnl_impl::fusion_info_mgr_t mgr;
7172
dnnl_impl::pd_cache_t pd_cache;
73+
const graph::fpmath_t fpm {graph::fpmath_mode::any, false};
7274
auto sg = std::make_shared<dnnl_impl::subgraph_t>(
73-
std::vector<std::shared_ptr<graph::op_t>> {op}, p_engine,
74-
graph::fpmath_mode::any, false, false);
75+
std::vector<std::shared_ptr<graph::op_t>> {op}, p_engine, fpm,
76+
false, false);
7577
dnnl_impl::subgraph_rewriter_t rewriter {sg};
7678
ASSERT_EQ(layout_propagator_for_reorder(
7779
op, p_engine, mgr, pd_cache, rewriter),
@@ -91,9 +93,10 @@ TEST(test_layout_propagator, LayoutPropagatorForSumDeathTest) {
9193

9294
op->add_input(lt_in);
9395
op->add_output(lt_out);
96+
const graph::fpmath_t fpm {graph::fpmath_mode::any, false};
9497
auto sg = std::make_shared<dnnl_impl::subgraph_t>(
95-
std::vector<std::shared_ptr<graph::op_t>> {op}, p_engine,
96-
graph::fpmath_mode::any, false, false);
98+
std::vector<std::shared_ptr<graph::op_t>> {op}, p_engine, fpm,
99+
false, false);
97100
dnnl_impl::subgraph_rewriter_t rewriter {sg};
98101
ASSERT_EQ(layout_propagator_for_sum(op, p_engine, mgr, pd_cache, rewriter),
99102
graph::status::success);
@@ -126,9 +129,10 @@ TEST(test_layout_propagator, LayoutPropagatorForSubZpsDeathTest) {
126129
dnnl_impl::fusion_info_mgr_t mgr;
127130
dnnl_impl::pd_cache_t pd_cache;
128131
auto op = std::make_shared<graph::op_t>(0, graph::op_kind::Wildcard, "op");
132+
const graph::fpmath_t fpm {graph::fpmath_mode::any, false};
129133
auto sg = std::make_shared<dnnl_impl::subgraph_t>(
130-
std::vector<std::shared_ptr<graph::op_t>> {op}, p_engine,
131-
graph::fpmath_mode::any, false, false);
134+
std::vector<std::shared_ptr<graph::op_t>> {op}, p_engine, fpm,
135+
false, false);
132136
dnnl_impl::subgraph_rewriter_t rewriter {sg};
133137
#ifndef NDEBUG
134138
EXPECT_DEATH(dnnl_impl::layout_propagator_for_sub_zps(
@@ -147,9 +151,10 @@ TEST(test_layout_propagator, LayoutPropagatorForAddZpsDeathTest) {
147151
dnnl_impl::fusion_info_mgr_t mgr;
148152
dnnl_impl::pd_cache_t pd_cache;
149153
auto op = std::make_shared<graph::op_t>(0, graph::op_kind::Wildcard, "op");
154+
const graph::fpmath_t fpm {graph::fpmath_mode::any, false};
150155
auto sg = std::make_shared<dnnl_impl::subgraph_t>(
151-
std::vector<std::shared_ptr<graph::op_t>> {op}, p_engine,
152-
graph::fpmath_mode::any, false, false);
156+
std::vector<std::shared_ptr<graph::op_t>> {op}, p_engine, fpm,
157+
false, false);
153158
dnnl_impl::subgraph_rewriter_t rewriter {sg};
154159
#ifndef NDEBUG
155160
EXPECT_DEATH(dnnl_impl::layout_propagator_for_add_zps(

tests/gtests/graph/unit/backend/dnnl/test_partition_cpu.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2020-2024 Intel Corporation
2+
* Copyright 2020-2025 Intel Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,19 +30,21 @@ using namespace dnnl::impl::graph;
3030
using namespace dnnl::graph::tests::unit::utils;
3131

3232
TEST(test_partition, CreateSimple) {
33+
const graph::fpmath_t fpm {fpmath_mode::strict, false};
3334
dnnl::impl::graph::dnnl_impl::dnnl_partition_impl_t p(
34-
engine_kind::cpu, fpmath_mode::strict, partition_kind_t::undef);
35+
engine_kind::cpu, fpm, partition_kind_t::undef);
3536
ASSERT_EQ(p.get_ops().size(), 0U);
36-
ASSERT_EQ(p.get_fpmath_mode(), fpmath_mode::strict);
37+
ASSERT_EQ(p.get_fpmath_mode().mode_, fpmath_mode::strict);
3738
ASSERT_EQ(p.get_kind(), partition_kind_t::undef);
3839
}
3940

4041
TEST(test_partition, AddOps) {
4142
std::vector<engine_kind_t> engine_kinds
4243
= {engine_kind::cpu, engine_kind::gpu};
44+
const graph::fpmath_t fpm {fpmath_mode::strict, false};
4345
for (const auto &engine_kind : engine_kinds) {
4446
dnnl::impl::graph::dnnl_impl::dnnl_partition_impl_t p(
45-
engine_kind, fpmath_mode::strict, partition_kind_t::undef);
47+
engine_kind, fpm, partition_kind_t::undef);
4648
size_t id = 100;
4749
std::shared_ptr<op_t> n(new op_t(id, op_kind::Wildcard, "Wildcard"));
4850
p.add_op(n);
@@ -60,8 +62,9 @@ TEST(test_partition, AddOps) {
6062
}
6163

6264
TEST(test_partition, GetOps) {
65+
const graph::fpmath_t fpm {fpmath_mode::strict, false};
6366
dnnl::impl::graph::dnnl_impl::dnnl_partition_impl_t p(
64-
engine_kind::cpu, fpmath_mode::strict, partition_kind_t::undef);
67+
engine_kind::cpu, fpm, partition_kind_t::undef);
6568
size_t id = 100;
6669
std::shared_ptr<op_t> n(new op_t(id, op_kind::Wildcard, "Wildcard"));
6770
p.add_op(n);
@@ -73,9 +76,10 @@ TEST(test_partition, GetOps) {
7376
TEST(test_partition, Init) {
7477
std::vector<engine_kind_t> engine_kinds
7578
= {engine_kind::cpu, engine_kind::gpu};
79+
const graph::fpmath_t fpm {fpmath_mode::strict, false};
7680
for (const auto &engine_kind : engine_kinds) {
7781
dnnl::impl::graph::dnnl_impl::dnnl_partition_impl_t p(
78-
engine_kind, fpmath_mode::strict, partition_kind_t::undef);
82+
engine_kind, fpm, partition_kind_t::undef);
7983
std::shared_ptr<op_t> n(new op_t(0, op_kind::Convolution, "Conv"));
8084
n->set_attr<int64_t>(op_attr::groups, 0);
8185
p.add_op(n);
@@ -87,9 +91,10 @@ TEST(test_partition, Init) {
8791
TEST(test_partition, Clone) {
8892
std::vector<engine_kind_t> engine_kinds
8993
= {engine_kind::cpu, engine_kind::gpu};
94+
const graph::fpmath_t fpm {fpmath_mode::strict, false};
9095
for (const auto &engine_kind : engine_kinds) {
91-
dnnl::impl::graph::dnnl_impl::dnnl_partition_impl_t p(engine_kind,
92-
fpmath_mode::strict, partition_kind_t::convolution_post_ops);
96+
dnnl::impl::graph::dnnl_impl::dnnl_partition_impl_t p(
97+
engine_kind, fpm, partition_kind_t::convolution_post_ops);
9398
auto n = std::make_shared<op_t>(op_kind::Convolution);
9499
n->set_attr<int64_t>(op_attr::groups, 1);
95100

@@ -120,11 +125,10 @@ TEST(test_partition_op, AssignedPartition) {
120125
op_t conv {0, op_kind::Convolution, std::string("convolution")};
121126

122127
ASSERT_EQ(conv.get_partition(), nullptr);
123-
128+
const graph::fpmath_t fpm {fpmath_mode::strict, false};
124129
auto part = std::make_shared<
125130
dnnl::impl::graph::dnnl_impl::dnnl_partition_impl_t>(
126-
engine_kind::cpu, fpmath_mode::strict,
127-
partition_kind_t::convolution_post_ops);
131+
engine_kind::cpu, fpm, partition_kind_t::convolution_post_ops);
128132
conv.set_partition(part.get());
129133
ASSERT_EQ(conv.get_partition(), part.get());
130134
}
@@ -133,9 +137,10 @@ TEST(test_partition, SetFpmathMode) {
133137
engine_t *eng = get_engine();
134138
for (auto m : {fpmath_mode::strict, fpmath_mode::bf16, fpmath_mode::f16,
135139
fpmath_mode::any}) {
140+
const graph::fpmath_t fpm {m, false};
136141
dnnl::impl::graph::dnnl_impl::dnnl_partition_impl_t p(
137-
eng->kind(), m, partition_kind_t::undef);
138-
ASSERT_EQ(p.get_fpmath_mode(), m);
142+
eng->kind(), fpm, partition_kind_t::undef);
143+
ASSERT_EQ(p.get_fpmath_mode().mode_, m);
139144
}
140145
}
141146

@@ -154,11 +159,10 @@ TEST(test_partition, InferShape) {
154159

155160
std::vector<const graph::logical_tensor_t *> inputs {&lt1, &lt2};
156161
std::vector<graph::logical_tensor_t *> outputs {&lt3};
157-
162+
const graph::fpmath_t fpm {fpmath_mode::strict, false};
158163
auto par = std::make_shared<
159164
dnnl::impl::graph::dnnl_impl::dnnl_partition_impl_t>(
160-
engine_kind, graph::fpmath_mode::strict,
161-
graph::partition_kind_t::undef);
165+
engine_kind, fpm, graph::partition_kind_t::undef);
162166
ASSERT_EQ(par->infer_shape(inputs, outputs), graph::status::success);
163167
}
164168
}

0 commit comments

Comments
 (0)