Skip to content

Commit

Permalink
Added if DEFINE construction
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyachur committed Dec 21, 2020
1 parent b2399ce commit 19ae269
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ TEST(ConditionalCompilationTests, SimpleScope) {
#undef CCTests_Scope0
}

TEST(ConditionalCompilationTests, SimpleSectionDefine) {
#define CCTests_Section1 1

int n = 0;
#if OV_SCOPE_DEFINE(CCTests, Section1)
OV_SCOPE_TASK(CCTests, Section1);
n = 42;
#endif
EXPECT_EQ(n, 42);

#if OV_SCOPE_DEFINE(CCTests, Section2)
n = 43;
#endif
EXPECT_EQ(n, 42);

#undef CCTests_Section1
}

TEST(ConditionalCompilationTests, SwitchCase) {
// Cases 0 and 2 are enabled
#define CCTests_TestTemplateClass 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ struct TestNode : public TestNodeBase {

} // namespace

TEST(ConditionalCompilationTests, SimpleSectionDefineAnalysys) {
int n = 0;

#if OV_SCOPE_DEFINE(CCTests, Section1)
OV_SCOPE_TASK(CCTests, Section1);
n = 42;
#endif
EXPECT_EQ(n, 42);

#if OV_SCOPE_DEFINE(CCTests, Section2)
n = 43;
#endif
EXPECT_EQ(n, 43);
}

TEST(ConditionalCompilationTests, SimpleScopeAnalysys) {
int n = 0;

Expand Down
4 changes: 0 additions & 4 deletions ngraph/core/include/ngraph/op/topk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ namespace ngraph
const PartialShape input_partial_shape,
const int64_t k) const;
void set_axis(const Rank input_rank, const int64_t axis);

private:
bool evaluate_topk(const HostTensorVector& outputs,
const HostTensorVector& inputs) const;
};
} // namespace v1

Expand Down
4 changes: 4 additions & 0 deletions ngraph/core/src/itt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ namespace ngraph
rc = copy_tensor<element::Type_t::a>(__VA_ARGS__)); \
} \
break;

#define NGRAPH_OP_SCOPE_DEFILE(region) OV_SCOPE_DEFINE(ngraph_op, region)

#define NGRAPH_OP_SCOPE_TASK(region) OV_SCOPE_TASK(ngraph_op, region)
11 changes: 4 additions & 7 deletions ngraph/core/src/op/topk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,10 @@ void op::v1::TopK::set_k(size_t k)
op::Constant::create(element::i64, Shape{}, {k})->output(0));
}

bool op::v1::TopK::evaluate_topk(const HostTensorVector& outputs,
const HostTensorVector& inputs) const
bool op::v1::TopK::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const
{
#if NGRAPH_OP_SCOPE_DEFILE(v1_TopK_evaluate)
NGRAPH_OP_SCOPE_TASK(v1_TopK_evaluate);
Shape arg_shape = inputs[0]->get_shape();
// 1. get axis, mode ( max/min), sort_type
size_t axis = ngraph::normalize_axis(this, m_axis, arg_shape.size());
Expand Down Expand Up @@ -490,11 +491,7 @@ bool op::v1::TopK::evaluate_topk(const HostTensorVector& outputs,
compute_max,
sort_type,
get_index_element_type());
}

bool op::v1::TopK::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const
{
NGRAPH_OP_SCOPE(v1_TopK_evaluate, return evaluate_topk(outputs, inputs));
#endif
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ bool match(char const *region, Ctx && ctx, T && val, Case && cs, Cases&&... case
OV_ITT_SCOPED_TASK(OV_CC_CAT(SIMPLE_, Module), OV_CC_TOSTRING(region)); \
__VA_ARGS__

#define OV_SCOPE_DEFINE(Module, region) 1
#define OV_SCOPE_TASK(Module, region) \
OV_ITT_SCOPED_TASK(OV_CC_CAT(SIMPLE_, Module), OV_CC_TOSTRING(region))

#define OV_SWITCH(Module, fn, ctx, val, ...) \
openvino::cc::internal::match<OV_CC_CAT(SWITCH_, Module), fn> \
(OV_CC_TOSTRING(fn), ctx, val, __VA_ARGS__);
Expand Down Expand Up @@ -233,9 +237,16 @@ bool match(char const *region, Ctx && ctx, T && val, Case && cs, Cases&&... case
// Scope is enabled
#define OV_CC_SCOPE_1(...) __VA_ARGS__

#define OV_CC_DEFINE_0() 0
#define OV_CC_DEFINE_1() 1

#define OV_SCOPE(Module, region, ...) \
OV_CC_EXPAND(OV_CC_CAT(OV_CC_SCOPE_, OV_CC_SCOPE_IS_ENABLED(OV_CC_CAT3(Module, _, region)))(__VA_ARGS__))

#define OV_SCOPE_DEFINE(Module, region) \
OV_CC_CAT(OV_CC_DEFINE_, OV_CC_SCOPE_IS_ENABLED(OV_CC_CAT3(Module, _, region)))()
#define OV_SCOPE_TASK(Module, region)

// Switch is disabled
#define OV_CC_SWITCH_0(Module, fn, ctx, val)

Expand All @@ -255,6 +266,9 @@ bool match(char const *region, Ctx && ctx, T && val, Case && cs, Cases&&... case

#define OV_SCOPE(Module, region, ...) __VA_ARGS__

#define OV_SCOPE_DEFINE(Module, region) 1
#define OV_SCOPE_TASK(Module, region)

#define OV_SWITCH(Module, fn, ctx, val, ...) \
openvino::cc::internal::match<fn>(ctx, val, __VA_ARGS__);

Expand Down

0 comments on commit 19ae269

Please sign in to comment.