Skip to content

Commit

Permalink
Enabled NCC for enums (openvinotoolkit#7038)
Browse files Browse the repository at this point in the history
* Enabled NCC for enums

* Fixed enum values

* Marked lower case enum as deprecated

* Fixed deprecated enums

* Disable deprecation for Windows and GCC < 6

* Try to fix build
  • Loading branch information
ilyachur authored Aug 13, 2021
1 parent 3913196 commit af8dc64
Show file tree
Hide file tree
Showing 22 changed files with 363 additions and 309 deletions.
6 changes: 4 additions & 2 deletions cmake/developer_package/ncc_naming_style/openvino.style
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ FunctionTemplate: '^(operator.+|\w+)$'
TypeAliasName: '^\w+$'
VariableReference: '^\w+$'

EnumName: '^[A-Z][\w]+$'
# excepts element_type
# TODO: Fix interpolate
EnumConstantName: '^([A-Z\d_]+|undefined|dynamic|boolean|bf16|f16|f32|f64|i4|i8|i16|i32|i64|u1|u4|u8|u16|u32|u64|asymmetric|align_corners|round_prefer_floor|round_prefer_ceil|floor|ceil|simple|nearest|linear|linear_onnx|cubic|area|scales|sizes|half_pixel|tf_half_pixel_for_nn|pytorch_half_pixel|asymetric)$'
# TODO: align
EnumConstantName: '^.*$'
EnumName: '^.*$'
UsingDeclaration: '^.*$'
TypedefName: '^.*$'

Expand Down
32 changes: 16 additions & 16 deletions inference-engine/src/cldnn_engine/ops/interpolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ namespace CLDNNPlugin {

static cldnn::coordinate_transformation_mode GetCoordinateTransformationMode(ngraph::op::v4::Interpolate::CoordinateTransformMode mode) {
switch (mode) {
case ngraph::op::v4::Interpolate::CoordinateTransformMode::half_pixel:
case ngraph::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL:
return cldnn::coordinate_transformation_mode::half_pixel;
case ngraph::op::v4::Interpolate::CoordinateTransformMode::pytorch_half_pixel:
case ngraph::op::v4::Interpolate::CoordinateTransformMode::PYTORCH_HALF_PIXEL:
return cldnn::coordinate_transformation_mode::pytorch_half_pixel;
case ngraph::op::v4::Interpolate::CoordinateTransformMode::asymmetric:
case ngraph::op::v4::Interpolate::CoordinateTransformMode::ASYMMETRIC:
return cldnn::coordinate_transformation_mode::asymmetric;
case ngraph::op::v4::Interpolate::CoordinateTransformMode::tf_half_pixel_for_nn:
case ngraph::op::v4::Interpolate::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN:
return cldnn::coordinate_transformation_mode::tf_half_pixel_for_nn;
case ngraph::op::v4::Interpolate::CoordinateTransformMode::align_corners:
case ngraph::op::v4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS:
return cldnn::coordinate_transformation_mode::align_corners;
}

Expand All @@ -32,15 +32,15 @@ static cldnn::coordinate_transformation_mode GetCoordinateTransformationMode(ngr

static cldnn::nearest_mode GetNearestMode(ngraph::op::v4::Interpolate::NearestMode mode) {
switch (mode) {
case ngraph::op::v4::Interpolate::NearestMode::round_prefer_floor:
case ngraph::op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR:
return cldnn::nearest_mode::round_prefer_floor;
case ngraph::op::v4::Interpolate::NearestMode::round_prefer_ceil:
case ngraph::op::v4::Interpolate::NearestMode::ROUND_PREFER_CEIL:
return cldnn::nearest_mode::round_prefer_ceil;
case ngraph::op::v4::Interpolate::NearestMode::floor:
case ngraph::op::v4::Interpolate::NearestMode::FLOOR:
return cldnn::nearest_mode::floor;
case ngraph::op::v4::Interpolate::NearestMode::ceil:
case ngraph::op::v4::Interpolate::NearestMode::CEIL:
return cldnn::nearest_mode::ceil;
case ngraph::op::v4::Interpolate::NearestMode::simple:
case ngraph::op::v4::Interpolate::NearestMode::SIMPLE:
return cldnn::nearest_mode::simple;
}

Expand All @@ -49,18 +49,18 @@ static cldnn::nearest_mode GetNearestMode(ngraph::op::v4::Interpolate::NearestMo

static cldnn::shape_calculation_mode GetShapeCalculationMode(ngraph::op::v4::Interpolate::ShapeCalcMode mode) {
switch (mode) {
case ngraph::op::v4::Interpolate::ShapeCalcMode::sizes: return cldnn::shape_calculation_mode::sizes;
case ngraph::op::v4::Interpolate::ShapeCalcMode::scales: return cldnn::shape_calculation_mode::scales;
case ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES: return cldnn::shape_calculation_mode::sizes;
case ngraph::op::v4::Interpolate::ShapeCalcMode::SCALES: return cldnn::shape_calculation_mode::scales;
}
IE_THROW() << "Unknown shape calculation mode: " << static_cast<int>(mode);
}

static cldnn::resample_type GetResampleType(ngraph::op::v4::Interpolate::InterpolateMode mode) {
switch (mode) {
case ngraph::op::v4::Interpolate::InterpolateMode::nearest: return cldnn::resample_type::nearest;
case ngraph::op::v4::Interpolate::InterpolateMode::linear: return cldnn::resample_type::caffe_bilinear;
case ngraph::op::v4::Interpolate::InterpolateMode::linear_onnx: return cldnn::resample_type::linear_onnx;
case ngraph::op::v4::Interpolate::InterpolateMode::cubic: return cldnn::resample_type::cubic;
case ngraph::op::v4::Interpolate::InterpolateMode::NEAREST: return cldnn::resample_type::nearest;
case ngraph::op::v4::Interpolate::InterpolateMode::LINEAR: return cldnn::resample_type::caffe_bilinear;
case ngraph::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX: return cldnn::resample_type::linear_onnx;
case ngraph::op::v4::Interpolate::InterpolateMode::CUBIC: return cldnn::resample_type::cubic;
}
IE_THROW() << "Unknown interpolation mode: " << static_cast<int>(mode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool InterpolateTransformation::isPrecisionPreserved(std::shared_ptr<Node> layer
std::shared_ptr<opset4::Interpolate> interpolate4 = as_type_ptr<opset4::Interpolate>(layer);
if (interpolate4) {
const auto attrs = interpolate4->get_attrs();
return attrs.mode == op::v4::Interpolate::InterpolateMode::nearest;
return attrs.mode == op::v4::Interpolate::InterpolateMode::NEAREST;
}

return false;
Expand Down Expand Up @@ -108,7 +108,7 @@ bool InterpolateTransformation::canBeTransformed(const TransformationContext& co
if (interpolate4) {
const auto interpAttrs = interpolate4->get_attrs();

if (interpAttrs.mode != op::v4::Interpolate::InterpolateMode::nearest) {
if (interpAttrs.mode != op::v4::Interpolate::InterpolateMode::NEAREST) {
return false;
}

Expand All @@ -126,7 +126,7 @@ bool InterpolateTransformation::canBeTransformed(const TransformationContext& co
}
}

if (interpAttrs.coordinate_transformation_mode == op::v4::Interpolate::CoordinateTransformMode::align_corners) {
if (interpAttrs.coordinate_transformation_mode == op::v4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool ngraph::pass::low_precision::MarkupPrecisions::isPrecisionPreserved(const s
std::shared_ptr<opset4::Interpolate> interpolate4 = as_type_ptr<opset4::Interpolate>(node);
if (interpolate4) {
const auto attrs = interpolate4->get_attrs();
return attrs.mode == op::v4::Interpolate::InterpolateMode::nearest;
return attrs.mode == op::v4::Interpolate::InterpolateMode::NEAREST;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ngraph::pass::ConvertInterpolate1ToInterpolate4::ConvertInterpolate1ToInterpolat
ngraph::opset4::Interpolate::InterpolateAttrs attrsV4;

if (attrsV0.mode == "nearest") {
attrsV4.mode = ngraph::opset4::Interpolate::InterpolateMode::nearest;
attrsV4.mode = ngraph::opset4::Interpolate::InterpolateMode::NEAREST;
} else if (attrsV0.mode == "linear") {
// If we write only
// attrsV4.mode = ngraph::op::v4::Interpolate::InterpolateMode::linear;
Expand All @@ -54,34 +54,34 @@ ngraph::pass::ConvertInterpolate1ToInterpolate4::ConvertInterpolate1ToInterpolat
// TODO: delete this conditional statement, when CPU will have
// optimized version of the 'linear' mode.
if (input_shape_rank < 5) {
attrsV4.mode = ngraph::op::v4::Interpolate::InterpolateMode::linear_onnx;
attrsV4.mode = ngraph::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX;
} else if (input_shape_rank == 5) {
attrsV4.mode = ngraph::op::v4::Interpolate::InterpolateMode::linear;
attrsV4.mode = ngraph::op::v4::Interpolate::InterpolateMode::LINEAR;
} else {
return false;
}
} else if (attrsV0.mode == "cubic") {
attrsV4.mode = ngraph::opset4::Interpolate::InterpolateMode::cubic;
attrsV4.mode = ngraph::opset4::Interpolate::InterpolateMode::CUBIC;
} else if (attrsV0.mode == "linear_onnx") {
attrsV4.mode = ngraph::opset4::Interpolate::InterpolateMode::linear_onnx;
attrsV4.mode = ngraph::opset4::Interpolate::InterpolateMode::LINEAR_ONNX;
} else {
return false;
}
attrsV4.shape_calculation_mode = ngraph::opset4::Interpolate::ShapeCalcMode::sizes;
attrsV4.nearest_mode = ngraph::opset4::Interpolate::NearestMode::simple;
attrsV4.shape_calculation_mode = ngraph::opset4::Interpolate::ShapeCalcMode::SIZES;
attrsV4.nearest_mode = ngraph::opset4::Interpolate::NearestMode::SIMPLE;
attrsV4.pads_begin = attrsV0.pads_begin;
attrsV4.pads_end = attrsV0.pads_end;
attrsV4.antialias = attrsV0.antialias;
attrsV4.coordinate_transformation_mode = ngraph::opset4::Interpolate::CoordinateTransformMode::asymmetric;
attrsV4.coordinate_transformation_mode = ngraph::opset4::Interpolate::CoordinateTransformMode::ASYMMETRIC;
attrsV4.cube_coeff = -0.75f;
if (attrsV0.align_corners) {
attrsV4.coordinate_transformation_mode = ngraph::opset4::Interpolate::CoordinateTransformMode::align_corners;
} else if ((attrsV4.mode == ngraph::op::v4::Interpolate::InterpolateMode::linear_onnx ||
attrsV4.mode == ngraph::op::v4::Interpolate::InterpolateMode::linear) &&
attrsV4.coordinate_transformation_mode = ngraph::opset4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS;
} else if ((attrsV4.mode == ngraph::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX ||
attrsV4.mode == ngraph::op::v4::Interpolate::InterpolateMode::LINEAR) &&
std::all_of(attrsV4.pads_begin.begin(), attrsV4.pads_begin.end(), [](size_t i){return i == 0;}) &&
std::all_of(attrsV4.pads_end.begin(), attrsV4.pads_end.end(), [](size_t i){return i == 0;}) &&
!(input_shape_rank - 2 == 2 && attrsV0.axes == AxisSet{2, 3})) {
attrsV4.coordinate_transformation_mode = ngraph::opset4::Interpolate::CoordinateTransformMode::half_pixel;
attrsV4.coordinate_transformation_mode = ngraph::opset4::Interpolate::CoordinateTransformMode::HALF_PIXEL;
}

auto interpolateV4 = std::make_shared<ngraph::opset4::Interpolate>(interpolationV0->input_value(0), interpolationV0->input_value(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ const std::vector<InterpolateTransformationTestValues> testValues {
LayerTransformation::createParamsU8I8(),
interpAttributes(),
interp4Attributes(
ngraph::op::v4::Interpolate::InterpolateMode::nearest,
ngraph::op::v4::Interpolate::CoordinateTransformMode::half_pixel,
ngraph::op::v4::Interpolate::InterpolateMode::NEAREST,
ngraph::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL,
{0, 0, 0, 0},
{0, 0, 0, 0}),
4,
Expand All @@ -453,8 +453,8 @@ const std::vector<InterpolateTransformationTestValues> testValues {
LayerTransformation::createParamsU8I8(),
interpAttributes(),
interp4Attributes(
ngraph::op::v4::Interpolate::InterpolateMode::nearest,
ngraph::op::v4::Interpolate::CoordinateTransformMode::half_pixel,
ngraph::op::v4::Interpolate::InterpolateMode::NEAREST,
ngraph::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL,
{0, 0, 0, 0},
{0, 0, 0, 0}),
4,
Expand All @@ -478,8 +478,8 @@ const std::vector<InterpolateTransformationTestValues> testValues {
LayerTransformation::createParamsU8I8(),
interpAttributes(),
interp4Attributes(
ngraph::op::v4::Interpolate::InterpolateMode::nearest,
ngraph::op::v4::Interpolate::CoordinateTransformMode::half_pixel,
ngraph::op::v4::Interpolate::InterpolateMode::NEAREST,
ngraph::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL,
{0, 0, 0, 0},
{0, 0, 0, 0}),
4,
Expand All @@ -503,8 +503,8 @@ const std::vector<InterpolateTransformationTestValues> testValues {
LayerTransformation::createParamsU8I8(),
interpAttributes(),
interp4Attributes(
ngraph::op::v4::Interpolate::InterpolateMode::nearest,
ngraph::op::v4::Interpolate::CoordinateTransformMode::half_pixel,
ngraph::op::v4::Interpolate::InterpolateMode::NEAREST,
ngraph::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL,
{0, 0, 0, 0},
{0, 0, 0, 0}),
4,
Expand All @@ -528,8 +528,8 @@ const std::vector<InterpolateTransformationTestValues> testValues {
LayerTransformation::createParamsU8I8(),
interpAttributes(),
interp4Attributes(
ngraph::op::v4::Interpolate::InterpolateMode::linear_onnx,
ngraph::op::v4::Interpolate::CoordinateTransformMode::half_pixel,
ngraph::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX,
ngraph::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL,
{0, 0, 0, 0},
{0, 0, 0, 0}),
4,
Expand All @@ -553,8 +553,8 @@ const std::vector<InterpolateTransformationTestValues> testValues {
LayerTransformation::createParamsU8I8(),
interpAttributes(),
interp4Attributes(
ngraph::op::v4::Interpolate::InterpolateMode::nearest,
ngraph::op::v4::Interpolate::CoordinateTransformMode::align_corners,
ngraph::op::v4::Interpolate::InterpolateMode::NEAREST,
ngraph::op::v4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS,
{0, 0, 0, 0},
{0, 0, 0, 0}),
4,
Expand All @@ -578,8 +578,8 @@ const std::vector<InterpolateTransformationTestValues> testValues {
LayerTransformation::createParamsU8I8(),
interpAttributes(),
interp4Attributes(
ngraph::op::v4::Interpolate::InterpolateMode::nearest,
ngraph::op::v4::Interpolate::CoordinateTransformMode::half_pixel,
ngraph::op::v4::Interpolate::InterpolateMode::NEAREST,
ngraph::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL,
{0, 0, 0, 1},
{0, 0, 1, 0}),
4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ TEST(TransformationTests, ConvertInterpolate1ToInterpolate4) {
auto default_scales_node = opset1::Constant::create(ngraph::element::f32, Shape{4}, {1.f, 1.f, 4.0f / 3.0f, 4.0f / 3.0f});
auto axes_node = opset1::Constant::create(ngraph::element::i64, Shape{4}, {0, 1, 2, 3});

auto interpolate4_attr = opset4::Interpolate::InterpolateAttrs(opset4::Interpolate::InterpolateMode::nearest,
opset4::Interpolate::ShapeCalcMode::sizes, std::vector<size_t>{0, 0, 0, 0}, std::vector<size_t>{0, 0, 0, 0},
opset4::Interpolate::CoordinateTransformMode::asymmetric, opset4::Interpolate::NearestMode::simple,
auto interpolate4_attr = opset4::Interpolate::InterpolateAttrs(opset4::Interpolate::InterpolateMode::NEAREST,
opset4::Interpolate::ShapeCalcMode::SIZES, std::vector<size_t>{0, 0, 0, 0}, std::vector<size_t>{0, 0, 0, 0},
opset4::Interpolate::CoordinateTransformMode::ASYMMETRIC, opset4::Interpolate::NearestMode::SIMPLE,
false, -0.75);

auto interpolate4 = std::make_shared<opset4::Interpolate>(data_node, out_shape_node, default_scales_node, axes_node, interpolate4_attr);
Expand Down Expand Up @@ -97,9 +97,9 @@ TEST(TransformationTests, ConvertInterpolate1ToInterpolate4_1) {
auto default_scales_node = opset1::Constant::create(ngraph::element::f32, Shape{2}, {4.0f / 3.0f, 4.0f / 3.0f});
auto axes_node = opset1::Constant::create(ngraph::element::i64, Shape{2}, {2, 3});

auto interpolate4_attr = opset4::Interpolate::InterpolateAttrs(opset4::Interpolate::InterpolateMode::linear_onnx,
opset4::Interpolate::ShapeCalcMode::sizes, std::vector<size_t>{0, 0, 0, 0}, std::vector<size_t>{0, 0, 0, 0},
opset4::Interpolate::CoordinateTransformMode::asymmetric, opset4::Interpolate::NearestMode::simple,
auto interpolate4_attr = opset4::Interpolate::InterpolateAttrs(opset4::Interpolate::InterpolateMode::LINEAR_ONNX,
opset4::Interpolate::ShapeCalcMode::SIZES, std::vector<size_t>{0, 0, 0, 0}, std::vector<size_t>{0, 0, 0, 0},
opset4::Interpolate::CoordinateTransformMode::ASYMMETRIC, opset4::Interpolate::NearestMode::SIMPLE,
true, -0.75);

auto interpolate4 = std::make_shared<opset4::Interpolate>(data_node, out_shape_node, default_scales_node, axes_node, interpolate4_attr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,38 @@ const std::vector<std::vector<size_t>> inShapes = {
};

const std::vector<ngraph::op::v4::Interpolate::InterpolateMode> modesWithoutNearest = {
ngraph::op::v4::Interpolate::InterpolateMode::linear,
ngraph::op::v4::Interpolate::InterpolateMode::linear_onnx,
ngraph::op::v4::Interpolate::InterpolateMode::cubic,
ngraph::op::v4::Interpolate::InterpolateMode::LINEAR,
ngraph::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX,
ngraph::op::v4::Interpolate::InterpolateMode::CUBIC,
};

const std::vector<ngraph::op::v4::Interpolate::InterpolateMode> nearestMode = {
ngraph::op::v4::Interpolate::InterpolateMode::nearest,
ngraph::op::v4::Interpolate::InterpolateMode::NEAREST,
};

const std::vector<ngraph::op::v4::Interpolate::CoordinateTransformMode> coordinateTransformModes = {
ngraph::op::v4::Interpolate::CoordinateTransformMode::tf_half_pixel_for_nn,
ngraph::op::v4::Interpolate::CoordinateTransformMode::pytorch_half_pixel,
ngraph::op::v4::Interpolate::CoordinateTransformMode::half_pixel,
ngraph::op::v4::Interpolate::CoordinateTransformMode::asymmetric,
ngraph::op::v4::Interpolate::CoordinateTransformMode::align_corners,
ngraph::op::v4::Interpolate::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN,
ngraph::op::v4::Interpolate::CoordinateTransformMode::PYTORCH_HALF_PIXEL,
ngraph::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL,
ngraph::op::v4::Interpolate::CoordinateTransformMode::ASYMMETRIC,
ngraph::op::v4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS,
};

const std::vector<ngraph::op::v4::Interpolate::ShapeCalcMode> shapeCalculationMode = {
ngraph::op::v4::Interpolate::ShapeCalcMode::sizes,
ngraph::op::v4::Interpolate::ShapeCalcMode::scales,
ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES,
ngraph::op::v4::Interpolate::ShapeCalcMode::SCALES,
};

const std::vector<ngraph::op::v4::Interpolate::NearestMode> nearestModes = {
ngraph::op::v4::Interpolate::NearestMode::simple,
ngraph::op::v4::Interpolate::NearestMode::round_prefer_floor,
ngraph::op::v4::Interpolate::NearestMode::floor,
ngraph::op::v4::Interpolate::NearestMode::ceil,
ngraph::op::v4::Interpolate::NearestMode::round_prefer_ceil,
ngraph::op::v4::Interpolate::NearestMode::SIMPLE,
ngraph::op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR,
ngraph::op::v4::Interpolate::NearestMode::FLOOR,
ngraph::op::v4::Interpolate::NearestMode::CEIL,
ngraph::op::v4::Interpolate::NearestMode::ROUND_PREFER_CEIL,
};

const std::vector<ngraph::op::v4::Interpolate::NearestMode> defaultNearestMode = {
ngraph::op::v4::Interpolate::NearestMode::round_prefer_floor,
ngraph::op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR,
};

const std::vector<std::vector<size_t>> pads = {
Expand Down
Loading

0 comments on commit af8dc64

Please sign in to comment.