OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[CPU] Reference and JIT Implementations for RGBtoNV12 and BGRtoNV12 (#38673)
Mostafa212808fd9b14
diff --git a/src/core/reference/include/openvino/reference/convert_color_nv12.hpp b/src/core/reference/include/openvino/reference/convert_color_nv12.hppindex 66c585c4383..1d2936e6856 100644--- a/src/core/reference/include/openvino/reference/convert_color_nv12.hpp+++ b/src/core/reference/include/openvino/reference/convert_color_nv12.hpp@@ -10,28 +10,11 @@#include "openvino/core/type/element_type_traits.hpp"#include "openvino/op/util/convert_color_i420_base.hpp"#include "openvino/op/util/convert_color_nv12_base.hpp"+#include "openvino/reference/utils/convert_color_util.hpp"namespace ov {namespace reference {-template <typename T>-std::tuple<T, T, T> yuv_pixel_to_rgb(float y_val, float u_val, float v_val) {- auto c = y_val - 16.f;- auto d = u_val - 128.f;- auto e = v_val - 128.f;- auto clip = [](float a) -> T {- if (std::is_integral<T>()) {- return static_cast<T>(std::min(std::max(std::round(a), 0.f), 255.f));- } else {- return static_cast<T>(std::min(std::max(a, 0.f), 255.f));- }- };- auto b = clip(1.164f * c + 2.018f * d);- auto g = clip(1.164f * c - 0.391f * d - 0.813f * e);- auto r = clip(1.164f * c + 1.596f * e);- return std::tuple<T, T, T>{r, g, b};-}-template <typename T>void color_convert_nv12(const T* arg_y,const T* arg_uv,diff --git a/src/core/reference/include/openvino/reference/convert_color_to_nv12.hpp b/src/core/reference/include/openvino/reference/convert_color_to_nv12.hppindex 9e063798d1c..3a861b75c1f 100644--- a/src/core/reference/include/openvino/reference/convert_color_to_nv12.hpp+++ b/src/core/reference/include/openvino/reference/convert_color_to_nv12.hpp@@ -4,44 +4,12 @@#pragma once-#include <algorithm>-#include <cmath>#include <cstddef>#include <tuple>-namespace ov::reference {--namespace func {--template <typename T>-T clip(double a) {- if constexpr (std::is_integral_v<T>) {- return static_cast<T>(std::min(std::max(std::round(a), 0.0), 255.0));- } else {- return static_cast<T>(std::min(std::max(a, 0.0), 255.0));- }-}+#include "openvino/reference/utils/convert_color_util.hpp"-template <typename T>-T round_cast(double a) {- if constexpr (std::is_integral_v<T>) {- return static_cast<T>(std::round(a));- } else {- return static_cast<T>(a);- }-}--template <typename T>-std::tuple<T, T, T> rgb_pixel_to_yuv(T r_val, T g_val, T b_val) {- const double r = static_cast<double>(r_val);- const double g = static_cast<double>(g_val);- const double b = static_cast<double>(b_val);- return {clip<T>(0.257 * r + 0.504 * g + 0.098 * b + 16.0),- clip<T>(-0.148 * r - 0.291 * g + 0.439 * b + 128.0),- clip<T>(0.439 * r - 0.368 * g - 0.071 * b + 128.0)};-}--} // namespace func+namespace ov::reference {template <typename T, bool IsRGB>void color_convert_to_nv12(const T* rgb_ptr,@@ -71,17 +39,16 @@ void color_convert_to_nv12(const T* rgb_ptr,size_t pixel_idx = (h + dh) * image_w + (w + dw);size_t rgb_idx = pixel_idx * 3;T y, u, v;- std::tie(y, u, v) = func::rgb_pixel_to_yuv<T>(rgb[rgb_idx + r_offset],- rgb[rgb_idx + 1],- rgb[rgb_idx + b_offset]);+ std::tie(y, u, v) =+ rgb_pixel_to_yuv<T>(rgb[rgb_idx + r_offset], rgb[rgb_idx + 1], rgb[rgb_idx + b_offset]);y_ptr[pixel_idx] = y;u_sum += static_cast<double>(u);v_sum += static_cast<double>(v);}}size_t uv_index = (h / 2) * image_w + w;- uv_ptr[uv_index] = func::round_cast<T>(u_sum / 4.0);- uv_ptr[uv_index + 1] = func::round_cast<T>(v_sum / 4.0);+ uv_ptr[uv_index] = round_cast<T>(u_sum / 4.0);+ uv_ptr[uv_index + 1] = round_cast<T>(v_sum / 4.0);}}}diff --git a/src/core/reference/include/openvino/reference/utils/convert_color_util.hpp b/src/core/reference/include/openvino/reference/utils/convert_color_util.hppnew file mode 100644index 00000000000..236872e1215--- /dev/null+++ b/src/core/reference/include/openvino/reference/utils/convert_color_util.hpp@@ -0,0 +1,59 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <algorithm>+#include <cmath>+#include <tuple>+#include <type_traits>++namespace ov::reference {++/// Clamp \p a to [0, 255]. For integral types the value is rounded first.+template <typename T>+T clamp_pixel(float a) {+ if constexpr (std::is_integral_v<T>) {+ return static_cast<T>(std::min(std::max(std::round(a), 0.0f), 255.0f));+ } else {+ return static_cast<T>(std::min(std::max(a, 0.0f), 255.0f));+ }+}++/// Cast \p a to T, rounding first for integral types.+template <typename T, typename U>+T round_cast(U a) {+ if constexpr (std::is_integral_v<T>) {+ return static_cast<T>(std::round(a));+ } else {+ return static_cast<T>(a);+ }+}++// Reference ITU-R BT.601-7 Section 2.5 for information on how+// the constants in the following two functions were derived.++/// Convert a single YUV pixel (BT.601 limited range) to (R, G, B).+template <typename T, typename U = float>+std::tuple<T, T, T> yuv_pixel_to_rgb(U y_val, U u_val, U v_val) {+ const auto c = static_cast<float>(y_val) - 16.f;+ const auto d = static_cast<float>(u_val) - 128.f;+ const auto e = static_cast<float>(v_val) - 128.f;+ return {clamp_pixel<T>(1.164f * c + 1.596f * e),+ clamp_pixel<T>(1.164f * c - 0.391f * d - 0.813f * e),+ clamp_pixel<T>(1.164f * c + 2.018f * d)};+}++/// Convert a single RGB pixel to (Y, U, V) using BT.601 limited range.+template <typename T, typename U = float>+std::tuple<T, T, T> rgb_pixel_to_yuv(U r_val, U g_val, U b_val) {+ const auto r = static_cast<float>(r_val);+ const auto g = static_cast<float>(g_val);+ const auto b = static_cast<float>(b_val);+ return {clamp_pixel<T>(0.257f * r + 0.504f * g + 0.098f * b + 16.f),+ clamp_pixel<T>(-0.148f * r - 0.291f * g + 0.439f * b + 128.f),+ clamp_pixel<T>(0.439f * r - 0.368f * g - 0.071f * b + 128.f)};+}++} // namespace ov::referencediff --git a/src/plugins/intel_cpu/src/cpu_types.cpp b/src/plugins/intel_cpu/src/cpu_types.cppindex 81b03ba7cd8..f6cf2e59ebc 100644--- a/src/plugins/intel_cpu/src/cpu_types.cpp+++ b/src/plugins/intel_cpu/src/cpu_types.cpp@@ -149,6 +149,8 @@ static const TypeToNameMap& get_type_to_name_tbl() {{"NV12toBGR", Type::ColorConvert},{"I420toRGB", Type::ColorConvert},{"I420toBGR", Type::ColorConvert},+ {"RGBtoNV12", Type::ColorConvert},+ {"BGRtoNV12", Type::ColorConvert},{"Col2Im", Type::Col2Im},{"MVN", Type::MVN},{"NormalizeL2", Type::NormalizeL2},@@ -557,6 +559,8 @@ std::string algToString(const Algorithm alg) {CASE(ColorConvertNV12toBGR);CASE(ColorConvertI420toRGB);CASE(ColorConvertI420toBGR);+ CASE(ColorConvertRGBtoNV12);+ CASE(ColorConvertBGRtoNV12);}#undef CASEreturn "Undefined";diff --git a/src/plugins/intel_cpu/src/cpu_types.h b/src/plugins/intel_cpu/src/cpu_types.hindex 4d694eaeb2a..0946d8ac12b 100644--- a/src/plugins/intel_cpu/src/cpu_types.h+++ b/src/plugins/intel_cpu/src/cpu_types.h@@ -304,6 +304,8 @@ enum class Algorithm : uint8_t {ColorConvertNV12toBGR,ColorConvertI420toRGB,ColorConvertI420toBGR,+ ColorConvertRGBtoNV12,+ ColorConvertBGRtoNV12,};extern const ov::intel_cpu::caseless_unordered_map<std::string, Type> type_to_name_tbl;diff --git a/src/plugins/intel_cpu/src/nodes/color_convert.cpp b/src/plugins/intel_cpu/src/nodes/color_convert.cppindex e67509d5dfa..38865e6d71f 100644--- a/src/plugins/intel_cpu/src/nodes/color_convert.cpp+++ b/src/plugins/intel_cpu/src/nodes/color_convert.cpp@@ -4,20 +4,20 @@#include "color_convert.h"-#include <algorithm>#include <cmath>#include <cstddef>#include <cstdint>#include <memory>#include <oneapi/dnnl/dnnl_common.hpp>#include <openvino/core/type.hpp>+#include <openvino/op/bgr_to_nv12.hpp>#include <openvino/op/i420_to_bgr.hpp>#include <openvino/op/i420_to_rgb.hpp>#include <openvino/op/nv12_to_bgr.hpp>#include <openvino/op/nv12_to_rgb.hpp>+#include <openvino/op/rgb_to_nv12.hpp>#include <string>#include <tuple>-#include <type_traits>#include <vector>#include "cpu_parallel.hpp"@@ -29,6 +29,7 @@#include "openvino/core/except.hpp"#include "openvino/core/node.hpp"#include "openvino/core/type/element_type.hpp"+#include "openvino/reference/utils/convert_color_util.hpp"#include "openvino/runtime/system_conf.hpp"#include "shape_inference/custom/color_convert.hpp"@@ -37,6 +38,7 @@# include <array># include <common/c_types_map.hpp>+# include <cpu/x64/cpu_isa_traits.hpp># include <cpu/x64/jit_generator.hpp># include "kernels/x64/jit_kernel.hpp"@@ -65,6 +67,12 @@ std::tuple<Algorithm, std::string> getAlgorithmFor(const std::shared_ptr<const oif (ov::is_type<ov::op::v8::I420toBGR>(op)) {return std::make_tuple(Algorithm::ColorConvertI420toBGR, std::string());}+ if (ov::is_type<ov::op::v17::RGBtoNV12>(op)) {+ return std::make_tuple(Algorithm::ColorConvertRGBtoNV12, std::string());+ }+ if (ov::is_type<ov::op::v17::BGRtoNV12>(op)) {+ return std::make_tuple(Algorithm::ColorConvertBGRtoNV12, std::string());+ }return std::make_tuple(Algorithm::Default, std::string("Type ") + op->get_type_name() + " is not supported.");}@@ -83,7 +91,8 @@ public:Converter::Converter(Node* node): Base(node,node->getAlgorithm() == Algorithm::ColorConvertNV12toRGB ||- node->getAlgorithm() == Algorithm::ColorConvertI420toRGB+ node->getAlgorithm() == Algorithm::ColorConvertI420toRGB ||+ node->getAlgorithm() == Algorithm::ColorConvertRGBtoNV12? ColorFormat{{0, 1, 2}}: ColorFormat{{2, 1, 0}}) {}@@ -91,23 +100,6 @@ bool Converter::singlePlane() const {return _node->getOriginalInputsNumber() == 1;}-template <typename T>-std::tuple<T, T, T> Converter::yuv_to_rgb(float y, float u, float v) {- auto c = y - 16.F;- auto d = u - 128.F;- auto e = v - 128.F;- auto clip = [](float a) -> T {- if (std::is_integral<T>()) {- return static_cast<T>(std::min(std::max(std::round(a), 0.F), 255.F));- }- return static_cast<T>(std::min(std::max(a, 0.F), 255.F));- };- auto r = clip(1.164F * c + 1.596F * e);- auto g = clip(1.164F * c - 0.391F * d - 0.813F * e);- auto b = clip(1.164F * c + 2.018F * d);- return std::make_tuple(r, g, b);-}-#if defined(OPENVINO_ARCH_X86_64)struct jit_uni_converter : public jit_kernel {DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_converter)@@ -212,9 +204,9 @@ void jit_uni_converter::yuv_to_rgb(const variable<float[N]>& y,return mask;};- r = r.permute(genPermutationMask(0));- g = g.permute(genPermutationMask(1));- b = b.permute(genPermutationMask(2));+ std::ignore = r.permute(genPermutationMask(0));+ std::ignore = g.permute(genPermutationMask(1));+ std::ignore = b.permute(genPermutationMask(2));auto blendWithMask = [&](int offset, const variable<float[N]>& result) {static const uint32_t blendMasks[2] = {0x92492492, 0x24924924};@@ -222,8 +214,8 @@ void jit_uni_converter::yuv_to_rgb(const variable<float[N]>& y,const auto mask1 = static_cast<uint16_t>(blendMasks[1] >> ((offset * N) % 3));result = r;- result = result.blend(g, mask0);- result = result.blend(b, mask1);+ std::ignore = result.blend(g, mask0);+ std::ignore = result.blend(b, mask1);};blendWithMask(0, r0);@@ -369,7 +361,7 @@ void RefConverter::convert(const T* y,auto uv_index = (h / 2) * width + (w / 2) * 2;auto u_val = static_cast<float>(uv_ptr[uv_index]);auto v_val = static_cast<float>(uv_ptr[uv_index + 1]);- auto [r, g, b] = yuv_to_rgb<T>(y_val, u_val, v_val);+ auto [r, g, b] = ov::reference::yuv_pixel_to_rgb<T>(y_val, u_val, v_val);out[y_index * 3 + _colorFormat[0]] = r;out[y_index * 3 + _colorFormat[1]] = g;out[y_index * 3 + _colorFormat[2]] = b;@@ -703,7 +695,7 @@ void RefConverter::convert(const T* y,auto uv_index = (h / 2) * (width / 2) + w / 2;auto u_val = static_cast<float>(u_ptr[uv_index]);auto v_val = static_cast<float>(v_ptr[uv_index]);- auto [r, g, b] = yuv_to_rgb<T>(y_val, u_val, v_val);+ auto [r, g, b] = ov::reference::yuv_pixel_to_rgb<T>(y_val, u_val, v_val);out[y_index * 3 + _colorFormat[0]] = r;out[y_index * 3 + _colorFormat[1]] = g;out[y_index * 3 + _colorFormat[2]] = b;@@ -856,8 +848,8 @@ JitConverter<T[N]>::load_yuv(const variable<const T*>& src_y,template <typename T, size_t N>void JitConverter<T[N]>::unpack_uv(const variable<float[N]>& u, const variable<float[N]>& v) {static const uint8_t order[] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};- u = u.permute(order);- v = v.permute(order);+ std::ignore = u.permute(order);+ std::ignore = v.permute(order);}template <typename T>@@ -970,6 +962,714 @@ public:#endif} // namespace i420+namespace to_nv12 {++ColorConvert::Converter::PrimitiveDescs supportedPrimitiveDescs(Node* node) {+ const LayoutType layout = LayoutType::ncsp;++ const ov::element::Type precision =+ node->getOriginalInputPrecisionAtPort(0) == ov::element::u8 ? ov::element::u8 : ov::element::f32;++ ColorConvert::Converter::PrimitiveDescs descs;++ std::vector<PortConfigurator> outConfigs(node->getOriginalOutputsNumber(), PortConfigurator{layout, precision});++ descs.emplace_back(std::vector<PortConfigurator>{{layout, precision}},+ outConfigs,+ ov::with_cpu_x86_sse42() ? impl_desc_type::jit_uni : impl_desc_type::ref,+ true);++ return descs;+}++template <typename T, impl_desc_type I>+class SinglePlaneConvert;+template <typename T, impl_desc_type I>+class TwoPlaneConvert;++class RefConverter : public ColorConvert::Converter {+ using Base = ColorConvert::Converter;++public:+ explicit RefConverter(Node* node)+ : Base(node,+ // RGBtoNV12: R is channel 0; BGRtoNV12: R is channel 2.+ node->getAlgorithm() == Algorithm::ColorConvertRGBtoNV12 ? ColorFormat{{0, 1, 2}}+ : ColorFormat{{2, 1, 0}}) {+ OPENVINO_ASSERT(node->getOriginalInputsNumber() == 1, "RGBtoNV12/BGRtoNV12 node must have exactly 1 input");+ const auto nout = node->getOriginalOutputsNumber();+ OPENVINO_ASSERT(nout == 1 || nout == 2, "RGBtoNV12/BGRtoNV12 node must have 1 or 2 outputs");+ }++protected:+ template <typename T>+ void convert(const T* src,+ T* dst_y,+ T* dst_uv,+ size_t batch_size,+ size_t height,+ size_t width,+ size_t stride_in,+ size_t stride_y,+ size_t stride_uv,+ const CpuParallelPtr& cpu_parallel) {+ const size_t r_idx = _colorFormat[0]; // RGB: 0, BGR: 2+ const size_t g_idx = _colorFormat[1]; // always 1+ const size_t b_idx = _colorFormat[2]; // RGB: 2, BGR: 0++ // Process pairs of rows so UV (2x2 subsampled) can be averaged over all 4 pixels.+ cpu_parallel->parallel_for2d(batch_size, height / 2, [&](int batch, int half_h) {+ const size_t h0 = static_cast<size_t>(half_h) * 2;+ const size_t h1 = h0 + 1;++ const T* src0 = src + static_cast<size_t>(batch) * stride_in + h0 * width * 3;+ const T* src1 = src + static_cast<size_t>(batch) * stride_in + h1 * width * 3;+ T* y_out0 = dst_y + static_cast<size_t>(batch) * stride_y + h0 * width;+ T* y_out1 = dst_y + static_cast<size_t>(batch) * stride_y + h1 * width;++ T* uv_out = dst_uv + static_cast<size_t>(batch) * stride_uv + static_cast<size_t>(half_h) * width;++ for (size_t w = 0; w < width; w += 2) {+ double u_sum = 0.0, v_sum = 0.0;++ auto process_pixel = [&](const T* row, T* y_row, size_t col) {+ T y_val, u_val, v_val;+ std::tie(y_val, u_val, v_val) = ov::reference::rgb_pixel_to_yuv<T>(row[(col * 3) + r_idx],+ row[(col * 3) + g_idx],+ row[(col * 3) + b_idx]);+ y_row[col] = y_val;+ u_sum += static_cast<double>(u_val);+ v_sum += static_cast<double>(v_val);+ };++ process_pixel(src0, y_out0, w);+ process_pixel(src0, y_out0, w + 1);+ process_pixel(src1, y_out1, w);+ process_pixel(src1, y_out1, w + 1);++ uv_out[w] = ov::reference::round_cast<T>(u_sum / 4.0); // U+ uv_out[w + 1] = ov::reference::round_cast<T>(v_sum / 4.0); // V+ }+ });+ }+};++template <typename T>+class SinglePlaneConvert<T, impl_desc_type::ref> : public RefConverter {+public:+ using RefConverter::RefConverter;++ void execute(const CpuParallelPtr& cpu_parallel, [[maybe_unused]] const dnnl::stream& strm) override {+ const auto& in_dims = inputDims(0);+ const size_t batch_size = in_dims[N_DIM];+ const size_t height = in_dims[H_DIM];+ const size_t width = in_dims[W_DIM];++ const T* src = static_cast<const T*>(input(0));+ T* dst = static_cast<T*>(output(0));++ const size_t out_stride = height * width * 3 / 2;++ convert<T>(src,+ dst,+ dst + height * width,+ batch_size,+ height,+ width,+ height * width * 3,+ out_stride,+ out_stride,+ cpu_parallel);+ }+};++template <typename T>+class TwoPlaneConvert<T, impl_desc_type::ref> : public RefConverter {+public:+ using RefConverter::RefConverter;++ void execute(const CpuParallelPtr& cpu_parallel, [[maybe_unused]] const dnnl::stream& strm) override {+ const auto& in_dims = inputDims(0);+ const size_t batch_size = in_dims[N_DIM];+ const size_t height = in_dims[H_DIM];+ const size_t width = in_dims[W_DIM];++ const T* src = static_cast<const T*>(input(0));+ T* dst_y = static_cast<T*>(output(0));+ T* dst_uv = static_cast<T*>(output(1));++ convert<T>(src,+ dst_y,+ dst_uv,+ batch_size,+ height,+ width,+ height * width * 3,+ height * width,+ height * width / 2,+ cpu_parallel);+ }+};++#if defined(OPENVINO_ARCH_X86_64)++struct jit_to_nv12_converter : public jit_kernel {+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_to_nv12_converter)+ struct Params {+ const void* src0; // interleaved RGB/BGR row 0+ const void* src1; // interleaved RGB/BGR row 1+ void* dst_y0; // Y output for row 0+ void* dst_y1; // Y output for row 1+ void* dst_uv; // interleaved UV output (width/2 pairs)+ size_t width; // pixels per row+ uint8_t colorFmt; // 0 = RGB input, else BGR input+ };++ using function_t = void (*)(const Params*);++ void init();++ void operator()(const Params& args) const {+ _fn(&args);+ }++protected:+ jit_to_nv12_converter();++ template <size_t N>+ void deinterleave(const variable<float[N]>& v0,+ const variable<float[N]>& v1,+ const variable<float[N]>& v2,+ const variable<float[N]>& ch0,+ const variable<float[N]>& ch1,+ const variable<float[N]>& ch2);++ template <size_t N>+ void rgb_to_yuv(const variable<float[N]>& r,+ const variable<float[N]>& g,+ const variable<float[N]>& b,+ const variable<float[N]>& y_out,+ const variable<float[N]>& u_out,+ const variable<float[N]>& v_out,+ bool do_round);++ function_t _fn = nullptr;+ variable<const float*> _consts;+};++jit_to_nv12_converter::jit_to_nv12_converter() : jit_kernel(jit_name()), _consts(*this) {}++void jit_to_nv12_converter::init() {+ OPENVINO_ASSERT(create_kernel() == status::success, "Can't generate jit RGB-to-NV12 converter kernel");+ _fn = reinterpret_cast<function_t>(const_cast<uint8_t*>(jit_ker()));+}++template <size_t N>+void jit_to_nv12_converter::deinterleave(const variable<float[N]>& v0,+ const variable<float[N]>& v1,+ const variable<float[N]>& v2,+ const variable<float[N]>& ch0,+ const variable<float[N]>& ch1,+ const variable<float[N]>& ch2) {+ auto extract_ch = [&](int ch, const variable<float[N]>& out) {+ std::array<uint8_t, N> perm0{};+ std::array<uint8_t, N> perm1{};+ std::array<uint8_t, N> perm2{};+ uint16_t mask_b = 0;+ uint16_t mask_c = 0;++ for (size_t p = 0; p < N; ++p) {+ size_t idx = (3 * p) + static_cast<size_t>(ch);+ size_t reg_id = idx / N;+ size_t lane = idx % N;++ if (reg_id == 0) {+ perm0[p] = static_cast<uint8_t>(lane);+ } else if (reg_id == 1) {+ perm1[p] = static_cast<uint8_t>(lane);+ mask_b |= static_cast<uint16_t>(1U << p);+ } else {+ perm2[p] = static_cast<uint8_t>(lane);+ mask_c |= static_cast<uint16_t>(1U << p);+ }+ }++ auto qa = var<float[N]>();+ auto qb = var<float[N]>();+ auto qc = var<float[N]>();+ qa = v0;+ qb = v1;+ qc = v2;++ std::ignore = qa.permute(perm0);+ std::ignore = qb.permute(perm1);+ std::ignore = qc.permute(perm2);++ out = qa;+ std::ignore = out.blend(qb, mask_b);+ std::ignore = out.blend(qc, mask_c);+ };++ extract_ch(0, ch0);+ extract_ch(1, ch1);+ extract_ch(2, ch2);+}++// BT.601 limited-range RGB->YUV constants:+// Y = 0.257R + 0.504G + 0.098B + 16+// U = -0.148R - 0.291G + 0.439B + 128+// V = 0.439R - 0.368G - 0.071B + 128+// Stored in _consts in order:+// [0] 0.257f [1] 0.504f [2] 0.098f [3] 16.f+// [4] -0.148f [5] 0.291f [6] 0.439f [7] 128.f+// [8] 0.368f [9] 0.071f [10] 255.f (clip ceil)++template <size_t N>+void jit_to_nv12_converter::rgb_to_yuv(const variable<float[N]>& r,+ const variable<float[N]>& g,+ const variable<float[N]>& b,+ const variable<float[N]>& y_out,+ const variable<float[N]>& u_out,+ const variable<float[N]>& v_out,+ bool do_round) {+ auto tmp = var<float[N]>();+ auto zero = var<float[N]>();+ auto ceil_val = var<float[N]>();+ auto half_val = var<float[N]>();++ uni_vxorps(zero, zero, zero);+ uni_vbroadcastss(ceil_val, ptr[_consts + 10 * sizeof(float)]);+ if (do_round) {+ uni_vbroadcastss(half_val, ptr[_consts + 12 * sizeof(float)]);+ }++ auto clip = [&](const variable<float[N]>& x) {+ if (do_round) {+ uni_vaddps(x, x, half_val);+ uni_vroundps(x, x, 1); // floor(x + 0.5f) to match std::round+ }+ uni_vmaxps(x, x, zero);+ uni_vminps(x, x, ceil_val);+ };++ uni_vbroadcastss(y_out, ptr[_consts + 0 * sizeof(float)]); // y = 0.257+ uni_vmulps(y_out, y_out, r); // y = 0.257R+ uni_vbroadcastss(tmp, ptr[_consts + 1 * sizeof(float)]); // tmp = 0.504+ uni_vmulps(tmp, tmp, g); // tmp = 0.504G+ uni_vaddps(y_out, y_out, tmp); // y += 0.504G+ uni_vbroadcastss(tmp, ptr[_consts + 2 * sizeof(float)]); // tmp = 0.098+ uni_vmulps(tmp, tmp, b); // tmp = 0.098B+ uni_vaddps(y_out, y_out, tmp); // y += 0.098B+ uni_vbroadcastss(tmp, ptr[_consts + 3 * sizeof(float)]); // tmp = 16+ uni_vaddps(y_out, y_out, tmp); // y += 16+ clip(y_out);++ uni_vbroadcastss(u_out, ptr[_consts + 4 * sizeof(float)]); // u = -0.148+ uni_vmulps(u_out, u_out, r); // u = -0.148R+ uni_vbroadcastss(tmp, ptr[_consts + 5 * sizeof(float)]); // tmp = 0.291+ uni_vmulps(tmp, tmp, g); // tmp = 0.291G+ uni_vsubps(u_out, u_out, tmp); // u = -0.148R - 0.291G+ uni_vbroadcastss(tmp, ptr[_consts + 6 * sizeof(float)]); // tmp = 0.439+ uni_vmulps(tmp, tmp, b); // tmp = 0.439B+ uni_vaddps(u_out, u_out, tmp); // u = -0.148R - 0.291G + 0.439B+ uni_vbroadcastss(tmp, ptr[_consts + 7 * sizeof(float)]); // tmp = 128+ uni_vaddps(u_out, u_out, tmp); // u += 128+ clip(u_out);++ uni_vbroadcastss(v_out, ptr[_consts + 6 * sizeof(float)]); // v = 0.439+ uni_vmulps(v_out, v_out, r); // v = 0.439R+ uni_vbroadcastss(tmp, ptr[_consts + 8 * sizeof(float)]); // tmp = 0.368+ uni_vmulps(tmp, tmp, g); // tmp = 0.368G+ uni_vsubps(v_out, v_out, tmp); // v -= 0.368G+ uni_vbroadcastss(tmp, ptr[_consts + 9 * sizeof(float)]); // tmp = 0.071+ uni_vmulps(tmp, tmp, b); // tmp = 0.071B+ uni_vsubps(v_out, v_out, tmp); // v -= 0.071B+ uni_vbroadcastss(tmp, ptr[_consts + 7 * sizeof(float)]); // tmp = 128+ uni_vaddps(v_out, v_out, tmp); // v += 128+ clip(v_out);+}++template <typename T>+class JitConverter;++template <typename T, size_t N>+class JitConverter<T[N]> : public jit_to_nv12_converter {+private:+ void generate() override;++ void load_rgb(const variable<const T*>& src,+ const variable<float[N]>& r,+ const variable<float[N]>& g,+ const variable<float[N]>& b,+ const variable<uint8_t>& color_fmt);++ void interleave_uv(const variable<float[N]>& u_sum,+ const variable<float[N]>& v_sum,+ const variable<float[N]>& uv_out,+ bool is_integral);+};++template <typename T, size_t N>+void JitConverter<T[N]>::load_rgb(const variable<const T*>& src,+ const variable<float[N]>& r,+ const variable<float[N]>& g,+ const variable<float[N]>& b,+ const variable<uint8_t>& color_fmt) {+ // Load 3 packed float registers covering N pixels of interleaved data.+ auto v0 = var<float[N]>();+ auto v1 = var<float[N]>();+ auto v2 = var<float[N]>();++ const size_t step = N * sizeof(T);+ load(v0, src);+ src += step;+ load(v1, src);+ src += step;+ load(v2, src);+ src += step;++ // Deinterleave into channel registers.+ // ch0 = first channel (R for RGB, B for BGR)+ // ch2 = last channel (B for RGB, R for BGR)+ auto ch0 = var<float[N]>();+ auto ch1 = var<float[N]>();+ auto ch2 = var<float[N]>();++ deinterleave(v0, v1, v2, ch0, ch1, ch2);++ // Assign R/G/B based on color format.+ _if(color_fmt == 0)+ ._then([&] {+ r = ch0; // ch0 = R+ g = ch1;+ b = ch2;+ })+ ._else([&] {+ b = ch0; // ch0 = B (BGR input)+ g = ch1;+ r = ch2;+ });+}++template <typename T, size_t N>+void JitConverter<T[N]>::interleave_uv(const variable<float[N]>& u_sum,+ const variable<float[N]>& v_sum,+ const variable<float[N]>& uv_out,+ bool is_integral) {+ auto gen_even_perm = []() {+ std::array<uint8_t, N> mask{};+ for (size_t i = 0; i < N; ++i) {+ mask[i] = static_cast<uint8_t>((i / 2) * 2);+ }+ return mask;+ };+ auto gen_odd_perm = []() {+ std::array<uint8_t, N> mask{};+ for (size_t i = 0; i < N; ++i) {+ mask[i] = static_cast<uint8_t>(((i / 2) * 2) + 1);+ }+ return mask;+ };++ const auto blend_mask = static_cast<uint16_t>(0xAAAAAAAAU & ((1U << N) - 1));++ auto even_sum = var<float[N]>();+ {+ auto u_even = var<float[N]>();+ auto v_even = var<float[N]>();+ u_even = u_sum;+ v_even = v_sum;+ std::ignore = u_even.permute(gen_even_perm());+ std::ignore = v_even.permute(gen_even_perm());+ even_sum = u_even;+ std::ignore = even_sum.blend(v_even, blend_mask);+ }++ auto odd_sum = var<float[N]>();+ {+ auto u_odd = var<float[N]>();+ auto v_odd = var<float[N]>();+ u_odd = u_sum;+ v_odd = v_sum;+ std::ignore = u_odd.permute(gen_odd_perm());+ std::ignore = v_odd.permute(gen_odd_perm());+ odd_sum = u_odd;+ std::ignore = odd_sum.blend(v_odd, blend_mask);+ }++ uni_vaddps(even_sum, even_sum, odd_sum);+ uv_out = even_sum;++ auto quarter = var<float[N]>();+ uni_vbroadcastss(quarter, ptr[_consts + 11 * sizeof(float)]); // 0.25f+ uni_vmulps(uv_out, uv_out, quarter);++ if (is_integral) {+ auto zero = var<float[N]>();+ auto ceil_val = var<float[N]>();+ auto half_val = var<float[N]>();+ uni_vxorps(zero, zero, zero);+ uni_vbroadcastss(ceil_val, ptr[_consts + 10 * sizeof(float)]);+ uni_vbroadcastss(half_val, ptr[_consts + 12 * sizeof(float)]);+ uni_vaddps(uv_out, uv_out, half_val);+ uni_vroundps(uv_out, uv_out, 1); // floor(x + 0.5f) to match std::round+ uni_vmaxps(uv_out, uv_out, zero);+ uni_vminps(uv_out, uv_out, ceil_val);+ }+}++template <typename T, size_t N>+void JitConverter<T[N]>::generate() {+ preamble();++ auto src0 = arg<const T*>(&Params::src0);+ auto src1 = arg<const T*>(&Params::src1);+ auto dst_y0 = arg<T*>(&Params::dst_y0);+ auto dst_y1 = arg<T*>(&Params::dst_y1);+ auto dst_uv = arg<T*>(&Params::dst_uv);+ auto width = arg(&Params::width);+ auto color_fmt = arg(&Params::colorFmt);++ static const float data[13] =+ {0.257F, 0.504F, 0.098F, 16.F, -0.148F, 0.291F, 0.439F, 128.F, 0.368F, 0.071F, 255.F, 0.25F, 0.5F};+ _consts = data;++ const auto reg_capacity_log = static_cast<size_t>(std::logb(N));+ const size_t y_step = N * sizeof(T);+ const size_t uv_step = N * sizeof(T);++ width >>= reg_capacity_log;++ foreach (0, width, [&]([[maybe_unused]] const variable<size_t>& /*idx*/) {+ auto u_sum = var<float[N]>();+ auto v_sum = var<float[N]>();++ // Row 0+ {+ auto r0 = var<float[N]>();+ auto g0 = var<float[N]>();+ auto b0 = var<float[N]>();+ load_rgb(src0, r0, g0, b0, color_fmt);++ auto y0 = var<float[N]>();+ auto v0 = var<float[N]>();+ rgb_to_yuv(r0, g0, b0, y0, u_sum, v0, std::is_integral_v<T>);++ store(dst_y0, y0);+ dst_y0 += y_step;++ v_sum = v0;+ }++ // Row 1+ {+ auto r1 = var<float[N]>();+ auto g1 = var<float[N]>();+ auto b1 = var<float[N]>();+ load_rgb(src1, r1, g1, b1, color_fmt);++ auto y1 = var<float[N]>();+ auto u1 = var<float[N]>();+ auto v1 = var<float[N]>();+ rgb_to_yuv(r1, g1, b1, y1, u1, v1, std::is_integral_v<T>);++ store(dst_y1, y1);+ dst_y1 += y_step;++ uni_vaddps(u_sum, u_sum, u1);+ uni_vaddps(v_sum, v_sum, v1);+ }++ auto uv_out = var<float[N]>();+ interleave_uv(u_sum, v_sum, uv_out, std::is_integral_v<T>);++ store(dst_uv, uv_out);+ dst_uv += uv_step;+ })+ ;++ // Tail: remaining pixels (width % N). NV12 requires even width, so tail is even.+ mov(width, argPtr(&Params::width));+ width &= N - 1;++ _if(width != 0)._then([&] {+ auto u_sumt = var<float[N]>();+ auto v_sumt = var<float[N]>();++ auto len = var<size_t>();+ mov(len, static_cast<const Xbyak::Reg64&>(width));+ const auto& len_reg = static_cast<const Xbyak::Reg64&>(len);+ lea(len_reg, ptr[len_reg + len_reg * 2]); // len = width * 3++ // Row 0 tail+ {+ auto s0 = stack(3 * N * sizeof(T));+ s0.clear();+ copy<T>(s0.pointer(), static_cast<const Xbyak::Reg64&>(src0), len);++ auto buf0 = var<const T*>();+ buf0 = s0.pointer();++ auto r0t = var<float[N]>();+ auto g0t = var<float[N]>();+ auto b0t = var<float[N]>();+ load_rgb(buf0, r0t, g0t, b0t, color_fmt);++ auto y0t = var<float[N]>();+ auto v0 = var<float[N]>();+ rgb_to_yuv(r0t, g0t, b0t, y0t, u_sumt, v0, std::is_integral_v<T>);++ store(dst_y0, y0t, width);++ v_sumt = v0;+ }++ // Row 1 tail+ {+ auto s1 = stack(3 * N * sizeof(T));+ s1.clear();+ copy<T>(s1.pointer(), static_cast<const Xbyak::Reg64&>(src1), len);++ auto buf1 = var<const T*>();+ buf1 = s1.pointer();++ auto r1t = var<float[N]>();+ auto g1t = var<float[N]>();+ auto b1t = var<float[N]>();+ load_rgb(buf1, r1t, g1t, b1t, color_fmt);++ auto y1t = var<float[N]>();+ auto u1t = var<float[N]>();+ auto fv1t = var<float[N]>();+ rgb_to_yuv(r1t, g1t, b1t, y1t, u1t, fv1t, std::is_integral_v<T>);++ store(dst_y1, y1t, width);++ uni_vaddps(u_sumt, u_sumt, u1t);+ uni_vaddps(v_sumt, v_sumt, fv1t);+ }++ auto uv_outt = var<float[N]>();+ interleave_uv(u_sumt, v_sumt, uv_outt, std::is_integral_v<T>);++ store(dst_uv, uv_outt, width);+ });++ postamble();+}++template <typename T>+const jit_to_nv12_converter& jit_to_nv12_create() {+ auto createKernel = []() {+ std::unique_ptr<jit_to_nv12_converter> kernel;+ if (mayiuse(cpu_isa_t::avx512_core)) {+ auto c = new JitConverter<T[16]>;+ kernel.reset(c);+ c->init();+ } else if (mayiuse(cpu_isa_t::avx2)) {+ auto c = new JitConverter<T[8]>;+ kernel.reset(c);+ c->init();+ } else if (mayiuse(cpu_isa_t::sse41)) {+ auto c = new JitConverter<T[4]>;+ kernel.reset(c);+ c->init();+ } else {+ OPENVINO_THROW("Can't create jit RGB-to-NV12 converter kernel");+ }+ return kernel;+ };+ static auto kernel = createKernel();+ return *kernel;+}++template <typename T>+const jit_to_nv12_converter& jit_to_nv12_get() {+ return jit_to_nv12_create<T>();+}++template <typename T>+class SinglePlaneConvert<T, impl_desc_type::jit_uni> : public RefConverter {+public:+ explicit SinglePlaneConvert(Node* node) : RefConverter(node) {+ jit_to_nv12_create<T>();+ }++ void execute(const CpuParallelPtr& cpu_parallel, [[maybe_unused]] const dnnl::stream& strm) override {+ const auto& kernel = jit_to_nv12_get<T>();+ const auto& in_dims = inputDims(0);+ const size_t batch = in_dims[N_DIM];+ const size_t height = in_dims[H_DIM];+ const size_t width = in_dims[W_DIM];++ const T* src = static_cast<const T*>(input(0));+ T* dst = static_cast<T*>(output(0));+ T* dst_y = dst;+ T* dst_uv = dst + height * width;++ const size_t stride_in = height * width * 3;+ const size_t stride_y = height * width * 3 / 2; // packed NV12 output stride+ const size_t stride_uv = height * width * 3 / 2;++ cpu_parallel->parallel_for2d(batch, height / 2, [&](int b, int half_h) {+ const size_t h0 = static_cast<size_t>(half_h) * 2;+ const size_t h1 = h0 + 1;++ typename jit_to_nv12_converter::Params args{+ src + static_cast<size_t>(b) * stride_in + h0 * width * 3,+ src + static_cast<size_t>(b) * stride_in + h1 * width * 3,+ dst_y + static_cast<size_t>(b) * stride_y + h0 * width,+ dst_y + static_cast<size_t>(b) * stride_y + h1 * width,+ dst_uv + static_cast<size_t>(b) * stride_uv + static_cast<size_t>(half_h) * width,+ width,+ _colorFormat[0]};+ kernel(args);+ });+ }+};++template <typename T>+class TwoPlaneConvert<T, impl_desc_type::jit_uni> : public RefConverter {+public:+ explicit TwoPlaneConvert(Node* node) : RefConverter(node) {+ jit_to_nv12_create<T>();+ }++ void execute(const CpuParallelPtr& cpu_parallel, [[maybe_unused]] const dnnl::stream& strm) override {+ const auto& kernel = jit_to_nv12_get<T>();+ const auto& in_dims = inputDims(0);+ const size_t batch = in_dims[N_DIM];+ const size_t height = in_dims[H_DIM];+ const size_t width = in_dims[W_DIM];++ const T* src = static_cast<const T*>(input(0));+ T* dst_y = static_cast<T*>(output(0));+ T* dst_uv = static_cast<T*>(output(1));++ const size_t stride_in = height * width * 3;+ const size_t stride_y = height * width;+ const size_t stride_uv = height * width / 2;++ cpu_parallel->parallel_for2d(batch, height / 2, [&](int b, int half_h) {+ const size_t h0 = static_cast<size_t>(half_h) * 2;+ const size_t h1 = h0 + 1;++ typename jit_to_nv12_converter::Params args{+ src + static_cast<size_t>(b) * stride_in + h0 * width * 3,+ src + static_cast<size_t>(b) * stride_in + h1 * width * 3,+ dst_y + static_cast<size_t>(b) * stride_y + h0 * width,+ dst_y + static_cast<size_t>(b) * stride_y + h1 * width,+ dst_uv + static_cast<size_t>(b) * stride_uv + static_cast<size_t>(half_h) * width,+ width,+ _colorFormat[0]};+ kernel(args);+ });+ }+};++#endif // OPENVINO_ARCH_X86_64++} // namespace to_nv12} // namespaceColorConvert::Converter::Converter(Node* node, const ColorFormat& colorFormat)@@ -1041,6 +1741,17 @@ void ColorConvert::initSupportedPrimitiveDescriptors() {initSupportedI420Impls();break;}+ case Algorithm::ColorConvertRGBtoNV12:+ case Algorithm::ColorConvertBGRtoNV12: {+ for (const auto& desc : to_nv12::supportedPrimitiveDescs(this)) {+ const auto& inPortConfigs = std::get<0>(desc);+ const auto& outPortConfigs = std::get<1>(desc);+ const auto implType = std::get<2>(desc);+ addSupportedPrimDesc(inPortConfigs, outPortConfigs, implType);+ }+ initSupportedtoNV12Impls();+ break;+ }default:break;}@@ -1102,6 +1813,34 @@ void ColorConvert::initSupportedI420Impls() {#undef SUPPORTED_IMPL}+void ColorConvert::initSupportedtoNV12Impls() {+#define SUPPORTED_IMPL(Impl, type, desc_type) \+ [](Node* node) { \+ return new to_nv12::Impl<type, impl_desc_type::desc_type>(node); \+ };++ // ref+ {+ auto& impls = _supportedImpls[impl_desc_type::ref][algorithm];+ impls[ov::element::Type_t::u8][true] = SUPPORTED_IMPL(SinglePlaneConvert, uint8_t, ref);+ impls[ov::element::Type_t::u8][false] = SUPPORTED_IMPL(TwoPlaneConvert, uint8_t, ref);+ impls[ov::element::Type_t::f32][true] = SUPPORTED_IMPL(SinglePlaneConvert, float, ref);+ impls[ov::element::Type_t::f32][false] = SUPPORTED_IMPL(TwoPlaneConvert, float, ref);+ }++#if defined(OPENVINO_ARCH_X86_64)+ // jit_uni+ {+ auto& impls = _supportedImpls[impl_desc_type::jit_uni][algorithm];+ impls[ov::element::Type_t::u8][true] = SUPPORTED_IMPL(SinglePlaneConvert, uint8_t, jit_uni);+ impls[ov::element::Type_t::u8][false] = SUPPORTED_IMPL(TwoPlaneConvert, uint8_t, jit_uni);+ impls[ov::element::Type_t::f32][true] = SUPPORTED_IMPL(SinglePlaneConvert, float, jit_uni);+ impls[ov::element::Type_t::f32][false] = SUPPORTED_IMPL(TwoPlaneConvert, float, jit_uni);+ }+#endif+#undef SUPPORTED_IMPL+}+void ColorConvert::createPrimitive() {const NodeDesc* desc = getSelectedPrimitiveDescriptor();CPU_NODE_ASSERT(desc, "has no optimal primitive descriptor selected");@@ -1109,7 +1848,13 @@ void ColorConvert::createPrimitive() {if (!_impl) {const auto& cfg = desc->getConfig();const auto precision = cfg.inConfs[0].getMemDesc()->getPrecision();- const bool isSinglePlane = cfg.inConfs.size() == 1;++ bool isSinglePlane = false;+ if (algorithm == Algorithm::ColorConvertRGBtoNV12 || algorithm == Algorithm::ColorConvertBGRtoNV12) {+ isSinglePlane = cfg.outConfs.size() == 1;+ } else {+ isSinglePlane = cfg.inConfs.size() == 1;+ }_impl = std::unique_ptr<Converter>(_supportedImpls.at(desc->getImplementationType()).at(algorithm).at(precision).at(isSinglePlane)(this));diff --git a/src/plugins/intel_cpu/src/nodes/color_convert.h b/src/plugins/intel_cpu/src/nodes/color_convert.hindex 49a9ffa56ee..3d62ed86da2 100644--- a/src/plugins/intel_cpu/src/nodes/color_convert.h+++ b/src/plugins/intel_cpu/src/nodes/color_convert.h@@ -43,6 +43,7 @@ public:private:void initSupportedNV12Impls();void initSupportedI420Impls();+ void initSupportedtoNV12Impls();using ConverterBuilder = std::function<Converter*(Node*)>;using SupportedImpls = multidim_map<impl_desc_type, // Implementation typediff --git a/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel.hpp b/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel.hppindex fb053080353..4271f45d322 100644--- a/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel.hpp+++ b/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_kernel.hpp@@ -310,6 +310,10 @@ public:}// NOLINTBEGIN(cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator)+ const variable& operator=(const variable& rhs) const {+ base::_kernel.mov(base::reg(), rhs.reg());+ return *this;+ }const variable& operator=(reg_type& rhs) const {base::_kernel.mov(base::reg(), rhs);return *this;@@ -521,6 +525,11 @@ public:explicit variable(jit_kernel& krnl);variable(jit_kernel& krnl, const shared_reg<reg_type>& reg);+ const variable& operator=(const variable& rhs) const {+ base::_kernel.uni_vmovups(base::reg(), rhs.reg());+ return *this;+ }+const variable& operator=(reg_type& rhs) const {base::_kernel.uni_vmovups(base::reg(), rhs);return *this;diff --git a/src/plugins/intel_cpu/src/shape_inference/custom/color_convert.cpp b/src/plugins/intel_cpu/src/shape_inference/custom/color_convert.cppindex 9798808df16..178611f9843 100644--- a/src/plugins/intel_cpu/src/shape_inference/custom/color_convert.cpp+++ b/src/plugins/intel_cpu/src/shape_inference/custom/color_convert.cpp@@ -14,6 +14,10 @@#include "cpu_memory.h"#include "cpu_types.h"#include "openvino/core/except.hpp"+#include "openvino/core/type.hpp"+#include "openvino/op/bgr_to_nv12.hpp"+#include "openvino/op/rgb_to_nv12.hpp"+#include "openvino/op/util/convert_color_to_nv12_base.hpp"#include "shape_inference/shape_inference_cpu.hpp"#include "shape_inference/shape_inference_status.hpp"@@ -28,7 +32,7 @@ Result ColorConvertShapeInfer::infer(const std::vector<std::reference_wrapper<co[[maybe_unused]] const std::unordered_map<size_t, MemoryPtr>& data_dependency) {const auto& dims = input_shapes.front().get();OPENVINO_ASSERT(dims.size() == 4, "NV12Converter node has incorrect input dimensions");- return {m_singlePlain ? std::vector<VectorDims>{{dims[ColorConvert::Converter::N_DIM],+ return {m_singlePlane ? std::vector<VectorDims>{{dims[ColorConvert::Converter::N_DIM],dims[ColorConvert::Converter::H_DIM] * 2 / 3,dims[ColorConvert::Converter::W_DIM],3}}@@ -39,8 +43,42 @@ Result ColorConvertShapeInfer::infer(const std::vector<std::reference_wrapper<coShapeInferStatus::success};}+Result ColorConvertToNV12ShapeInfer::infer(+ const std::vector<std::reference_wrapper<const VectorDims>>& input_shapes,+ [[maybe_unused]] const std::unordered_map<size_t, MemoryPtr>& data_dependency) {+ const auto& dims = input_shapes.front().get();+ OPENVINO_ASSERT(dims.size() == 4, "RGBtoNV12/BGRtoNV12 node expects 4 input dimensions");+ OPENVINO_ASSERT(dims[ColorConvert::Converter::C_DIM] == 3, "RGB/BGR input number of channels should be equal to 3");+ OPENVINO_ASSERT(dims[ColorConvert::Converter::H_DIM] % 2 == 0, "Image height must be even");+ OPENVINO_ASSERT(dims[ColorConvert::Converter::W_DIM] % 2 == 0, "Image width must be even");++ if (m_singlePlane) {+ // Single-plane output: [N, H*3/2, W, 1]+ return {{VectorDims{dims[ColorConvert::Converter::N_DIM],+ dims[ColorConvert::Converter::H_DIM] * 3 / 2,+ dims[ColorConvert::Converter::W_DIM],+ 1}},+ ShapeInferStatus::success};+ }+ // Two-plane output: Y=[N, H, W, 1] UV=[N, H/2, W/2, 2]+ return {{VectorDims{dims[ColorConvert::Converter::N_DIM],+ dims[ColorConvert::Converter::H_DIM],+ dims[ColorConvert::Converter::W_DIM],+ 1},+ VectorDims{dims[ColorConvert::Converter::N_DIM],+ dims[ColorConvert::Converter::H_DIM] / 2,+ dims[ColorConvert::Converter::W_DIM] / 2,+ 2}},+ ShapeInferStatus::success};+}+ShapeInferPtr ColorConvertShapeInferFactory::makeShapeInfer() const {- bool isSinglePlain = m_op->get_input_size() == 1;- return std::make_shared<ColorConvertShapeInfer>(isSinglePlain);+ if (ov::is_type<ov::op::v17::RGBtoNV12>(m_op) || ov::is_type<ov::op::v17::BGRtoNV12>(m_op)) {+ const auto base = ov::as_type_ptr<ov::op::util::ConvertColorToNV12Base>(m_op);+ const bool isSinglePlane = base && base->is_single_plane();+ return std::make_shared<ColorConvertToNV12ShapeInfer>(isSinglePlane);+ }+ bool isSinglePlane = m_op->get_input_size() == 1;+ return std::make_shared<ColorConvertShapeInfer>(isSinglePlane);}} // namespace ov::intel_cpu::nodediff --git a/src/plugins/intel_cpu/src/shape_inference/custom/color_convert.hpp b/src/plugins/intel_cpu/src/shape_inference/custom/color_convert.hppindex c06a43d8b62..0fada8aacc4 100644--- a/src/plugins/intel_cpu/src/shape_inference/custom/color_convert.hpp+++ b/src/plugins/intel_cpu/src/shape_inference/custom/color_convert.hpp@@ -2,6 +2,8 @@// SPDX-License-Identifier: Apache-2.0//+#pragma once+#include <cstddef>#include <functional>#include <memory>@@ -14,8 +16,6 @@#include "openvino/core/node.hpp"#include "shape_inference/shape_inference_cpu.hpp"-#pragma once-namespace ov::intel_cpu::node {using Result = IShapeInfer::Result;@@ -26,7 +26,20 @@ using Result = IShapeInfer::Result;*/class ColorConvertShapeInfer : public ShapeInferEmptyPads {public:- explicit ColorConvertShapeInfer(bool singlePlain) : m_singlePlain(singlePlain) {}+ explicit ColorConvertShapeInfer(bool singlePlane) : m_singlePlane(singlePlane) {}+ Result infer(const std::vector<std::reference_wrapper<const VectorDims>>& input_shapes,+ const std::unordered_map<size_t, MemoryPtr>& data_dependency) override;+ [[nodiscard]] port_mask_t get_port_mask() const override {+ return EMPTY_PORT_MASK;+ }++private:+ bool m_singlePlane = false;+};++class ColorConvertToNV12ShapeInfer : public ShapeInferEmptyPads {+public:+ explicit ColorConvertToNV12ShapeInfer(bool singlePlane) : m_singlePlane(singlePlane) {}Result infer(const std::vector<std::reference_wrapper<const VectorDims>>& input_shapes,const std::unordered_map<size_t, MemoryPtr>& data_dependency) override;[[nodiscard]] port_mask_t get_port_mask() const override {@@ -34,7 +47,7 @@ public:}private:- bool m_singlePlain = false;+ bool m_singlePlane = true;};class ColorConvertShapeInferFactory : public ShapeInferFactory {diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_to_nv12.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_to_nv12.cppnew file mode 100644index 00000000000..354e744dfd1--- /dev/null+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_to_nv12.cpp@@ -0,0 +1,59 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "single_op_tests/convert_color_to_nv12.hpp"++#include <vector>++#include "common_test_utils/test_constants.hpp"+#include "gtest/gtest.h"++namespace {+using ov::test::ConvertColorToNV12LayerTest;++const std::vector<std::vector<ov::Shape>> in_shapes = {{{1, 10, 10, 3}}};++const std::vector<ov::element::Type> inTypes = {ov::element::u8, ov::element::f32};++const std::vector<std::vector<ov::Shape>> in_shapes_acc = {{{1, 16 * 6, 16, 3}}};++const std::vector<std::vector<ov::Shape>> in_shapes_nightly = {{{1, 256 * 256, 256, 3}}};++const auto test_case_values =+ ::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes)),+ ::testing::ValuesIn(inTypes),+ ::testing::Bool(),+ ::testing::Bool(),+ ::testing::Values(ov::test::utils::DEVICE_CPU));++INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorToNV12,+ ConvertColorToNV12LayerTest,+ test_case_values,+ ConvertColorToNV12LayerTest::getTestCaseName);++const auto testCase_accuracy_values =+ ::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_acc)),+ ::testing::Values(ov::element::u8),+ ::testing::Bool(),+ ::testing::Bool(),+ ::testing::Values(ov::test::utils::DEVICE_CPU));++INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorToNV12_acc,+ ConvertColorToNV12LayerTest,+ testCase_accuracy_values,+ ConvertColorToNV12LayerTest::getTestCaseName);++const auto testCase_accuracy_values_nightly =+ ::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_nightly)),+ ::testing::Values(ov::element::u8),+ ::testing::Bool(),+ ::testing::Bool(),+ ::testing::Values(ov::test::utils::DEVICE_CPU));++INSTANTIATE_TEST_SUITE_P(nightly_TestsConvertColorToNV12_acc,+ ConvertColorToNV12LayerTest,+ testCase_accuracy_values_nightly,+ ConvertColorToNV12LayerTest::getTestCaseName);++} // namespacediff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cppindex ad6e0cb71bb..9c84e5e353f 100644--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp@@ -65,8 +65,6 @@ const std::vector<std::regex>& disabled_test_patterns() {std::regex(R"(.*OVClassQueryModelTest.*QueryModelWithDeviceID.*)"),// Issue 67214std::regex(R"(smoke_PrePostProcess.*resize_and_convert_layout_i8.*)"),- // TODO: Implement RGBtoNV12/BGRtoNV12 in CPU plugin.- std::regex(R"(.*smoke_PostProcess.*convert_color_(rgb|bgr)_to_nv12.*)"),// Issue: 69086// need to add support convert BIN -> FP32// if we set output precision as BIN, when we create output blob precision looks like UNSPECIFIEDdiff --git a/src/plugins/intel_cpu/tests/functional/sources.cmake b/src/plugins/intel_cpu/tests/functional/sources.cmakeindex 60aa4a2b500..36fb0dfbb32 100644--- a/src/plugins/intel_cpu/tests/functional/sources.cmake+++ b/src/plugins/intel_cpu/tests/functional/sources.cmake@@ -488,6 +488,7 @@ set(CPU_FUNC_TESTS_SRCS${CMAKE_CURRENT_LIST_DIR}/shared_tests_instances/single_layer_tests/conversion.cpp${CMAKE_CURRENT_LIST_DIR}/shared_tests_instances/single_layer_tests/convert_color_i420.cpp${CMAKE_CURRENT_LIST_DIR}/shared_tests_instances/single_layer_tests/convert_color_nv12.cpp+ ${CMAKE_CURRENT_LIST_DIR}/shared_tests_instances/single_layer_tests/convert_color_to_nv12.cpp${CMAKE_CURRENT_LIST_DIR}/shared_tests_instances/single_layer_tests/convolution_backprop_data.cpp${CMAKE_CURRENT_LIST_DIR}/shared_tests_instances/single_layer_tests/convolution.cpp${CMAKE_CURRENT_LIST_DIR}/shared_tests_instances/single_layer_tests/ctc_greedy_decoder.cppdiff --git a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/color_covert_shape_inference.cpp b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/color_covert_shape_inference.cppindex a84a95e2abf..0445c9611e6 100644--- a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/color_covert_shape_inference.cpp+++ b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/color_covert_shape_inference.cpp@@ -6,11 +6,13 @@#include "common_test_utils/test_assertions.hpp"#include "custom_shape_infer.hpp"+#include "openvino/op/bgr_to_nv12.hpp"#include "openvino/op/i420_to_bgr.hpp"#include "openvino/op/i420_to_rgb.hpp"#include "openvino/op/nv12_to_bgr.hpp"#include "openvino/op/nv12_to_rgb.hpp"#include "openvino/op/parameter.hpp"+#include "openvino/op/rgb_to_nv12.hpp"namespace ov {namespace intel_cpu {namespace unit_test {@@ -107,6 +109,86 @@ REGISTER_TYPED_TEST_SUITE_P(CpuShapeInferenceTest_ColorConvertI420,INSTANTIATE_TYPED_TEST_SUITE_P(CpuShapeInfer_I420toBGR, CpuShapeInferenceTest_ColorConvertI420, ::testing::Types<op::v8::I420toBGR>);INSTANTIATE_TYPED_TEST_SUITE_P(CpuShapeInfer_I420toRGB, CpuShapeInferenceTest_ColorConvertI420, ::testing::Types<op::v8::I420toRGB>);+template <class T>+class CpuShapeInferenceTest_ColorConvertToNV12 : public testing::Test {};++TYPED_TEST_SUITE_P(CpuShapeInferenceTest_ColorConvertToNV12);++TYPED_TEST_P(CpuShapeInferenceTest_ColorConvertToNV12, singlePlane) {+ auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto op = std::make_shared<TypeParam>(data, true);+ std::vector<StaticShape> static_input_shapes = {StaticShape{1, 480, 640, 3}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{1, 720, 640, 1}};+ unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes);+}++TYPED_TEST_P(CpuShapeInferenceTest_ColorConvertToNV12, multiPlane) {+ auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto op = std::make_shared<TypeParam>(data, false);+ std::vector<StaticShape> static_input_shapes = {StaticShape{1, 480, 640, 3}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{1, 480, 640, 1}, StaticShape{1, 240, 320, 2}};+ unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes);+}++TYPED_TEST_P(CpuShapeInferenceTest_ColorConvertToNV12, invalid_rank) {+ auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto op = std::make_shared<TypeParam>(data, false);+ std::vector<StaticShape> static_input_shapes = {StaticShape{480, 640, 3}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{}, StaticShape{}};++ OV_EXPECT_THROW(unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes),+ ov::Exception,+ testing::HasSubstr("RGBtoNV12/BGRtoNV12 node expects 4 input dimensions"));+}++TYPED_TEST_P(CpuShapeInferenceTest_ColorConvertToNV12, invalid_channels) {+ auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto op = std::make_shared<TypeParam>(data, true);+ std::vector<StaticShape> static_input_shapes = {StaticShape{1, 4, 4, 2}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{}};++ OV_EXPECT_THROW(unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes),+ ov::Exception,+ testing::HasSubstr("RGB/BGR input number of channels should be equal to 3"));+}++TYPED_TEST_P(CpuShapeInferenceTest_ColorConvertToNV12, odd_height) {+ auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto op = std::make_shared<TypeParam>(data, false);+ std::vector<StaticShape> static_input_shapes = {StaticShape{1, 5, 4, 3}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{}, StaticShape{}};++ OV_EXPECT_THROW(unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes),+ ov::Exception,+ testing::HasSubstr("Image height must be even"));+}++TYPED_TEST_P(CpuShapeInferenceTest_ColorConvertToNV12, odd_width) {+ auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto op = std::make_shared<TypeParam>(data, false);+ std::vector<StaticShape> static_input_shapes = {StaticShape{1, 4, 3, 3}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{}, StaticShape{}};++ OV_EXPECT_THROW(unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes),+ ov::Exception,+ testing::HasSubstr("Image width must be even"));+}++REGISTER_TYPED_TEST_SUITE_P(CpuShapeInferenceTest_ColorConvertToNV12,+ singlePlane,+ multiPlane,+ invalid_rank,+ invalid_channels,+ odd_height,+ odd_width);++INSTANTIATE_TYPED_TEST_SUITE_P(CpuShapeInfer_RGBtoNV12,+ CpuShapeInferenceTest_ColorConvertToNV12,+ ::testing::Types<op::v17::RGBtoNV12>);+INSTANTIATE_TYPED_TEST_SUITE_P(CpuShapeInfer_BGRtoNV12,+ CpuShapeInferenceTest_ColorConvertToNV12,+ ::testing::Types<op::v17::BGRtoNV12>);+} // namespace cpu_shape_infer} // namespace unit_test} // namespace intel_cpudiff --git a/src/plugins/intel_cpu/tests/unit/shape_inference_test/rgb_bgr_to_nv12_shape_inference_test.cpp b/src/plugins/intel_cpu/tests/unit/shape_inference_test/rgb_bgr_to_nv12_shape_inference_test.cppnew file mode 100644index 00000000000..a36e79ebcc4--- /dev/null+++ b/src/plugins/intel_cpu/tests/unit/shape_inference_test/rgb_bgr_to_nv12_shape_inference_test.cpp@@ -0,0 +1,144 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <gmock/gmock.h>++#include "common_test_utils/test_assertions.hpp"+#include "openvino/op/bgr_to_nv12.hpp"+#include "openvino/op/rgb_to_nv12.hpp"+#include "utils.hpp"++using namespace ov;+using namespace ov::intel_cpu;+using namespace testing;++template <class TOp>+class ConvertColorToNV12Test : public OpStaticShapeInferenceTest<TOp> {};++TYPED_TEST_SUITE_P(ConvertColorToNV12Test);++TYPED_TEST_P(ConvertColorToNV12Test, single_plane_default) {+ const auto rgb = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 4, 6, 3});+ this->op = this->make_op(rgb);++ this->input_shapes = StaticShapeVector{{3, 4, 6, 3}};+ auto output_shapes = shape_inference(this->op.get(), this->input_shapes);++ EXPECT_EQ(output_shapes.size(), 1);+ EXPECT_EQ(output_shapes[0], StaticShape({3, 6, 6, 1})); // H*3/2 = 4*3/2 = 6+}++TYPED_TEST_P(ConvertColorToNV12Test, single_plane_explicit) {+ const auto rgb = std::make_shared<op::v0::Parameter>(element::u8, PartialShape{1, 8, 10, 3});+ this->op = this->make_op(rgb, true);++ this->input_shapes = StaticShapeVector{{1, 8, 10, 3}};+ auto output_shapes = shape_inference(this->op.get(), this->input_shapes);++ EXPECT_EQ(output_shapes.size(), 1);+ EXPECT_EQ(output_shapes[0], StaticShape({1, 12, 10, 1})); // H*3/2 = 8*3/2 = 12+}++TYPED_TEST_P(ConvertColorToNV12Test, two_plane) {+ const auto rgb = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 480, 640, 3});+ this->op = this->make_op(rgb, false);++ this->input_shapes = StaticShapeVector{{2, 480, 640, 3}};+ auto output_shapes = shape_inference(this->op.get(), this->input_shapes);++ EXPECT_EQ(output_shapes.size(), 2);+ EXPECT_EQ(output_shapes[0], StaticShape({2, 480, 640, 1})); // Y plane+ EXPECT_EQ(output_shapes[1], StaticShape({2, 240, 320, 2})); // UV plane+}++TYPED_TEST_P(ConvertColorToNV12Test, single_plane_dynamic_rank) {+ const auto rgb = std::make_shared<op::v0::Parameter>(element::f32, PartialShape::dynamic());+ this->op = this->make_op(rgb);++ this->input_shapes = StaticShapeVector{{1, 6, 8, 3}};+ auto output_shapes = shape_inference(this->op.get(), this->input_shapes);++ EXPECT_EQ(output_shapes.size(), 1);+ EXPECT_EQ(output_shapes[0], StaticShape({1, 9, 8, 1})); // H*3/2 = 6*3/2 = 9+}++TYPED_TEST_P(ConvertColorToNV12Test, single_plane_static_rank) {+ const auto rgb = std::make_shared<op::v0::Parameter>(element::f32, PartialShape::dynamic(4));+ this->op = this->make_op(rgb);++ this->input_shapes = StaticShapeVector{{5, 2, 2, 3}};+ auto output_shapes = shape_inference(this->op.get(), this->input_shapes);++ EXPECT_EQ(output_shapes.size(), 1);+ EXPECT_EQ(output_shapes.front(), StaticShape({5, 3, 2, 1}));+}++TYPED_TEST_P(ConvertColorToNV12Test, two_plane_dynamic_rank) {+ const auto rgb = std::make_shared<op::v0::Parameter>(element::f32, PartialShape::dynamic());+ this->op = this->make_op(rgb, false);++ this->input_shapes = StaticShapeVector{{3, 10, 10, 3}};+ auto output_shapes = shape_inference(this->op.get(), this->input_shapes);++ EXPECT_EQ(output_shapes.size(), 2);+ EXPECT_EQ(output_shapes[0], StaticShape({3, 10, 10, 1}));+ EXPECT_EQ(output_shapes[1], StaticShape({3, 5, 5, 2}));+}++TYPED_TEST_P(ConvertColorToNV12Test, two_plane_static_rank) {+ const auto rgb = std::make_shared<op::v0::Parameter>(element::f32, PartialShape::dynamic(4));+ this->op = this->make_op(rgb, false);++ this->input_shapes = StaticShapeVector{{5, 20, 20, 3}};+ auto output_shapes = shape_inference(this->op.get(), this->input_shapes);++ EXPECT_EQ(output_shapes.size(), 2);+ EXPECT_EQ(output_shapes[0], StaticShape({5, 20, 20, 1}));+ EXPECT_EQ(output_shapes[1], StaticShape({5, 10, 10, 2}));+}++TYPED_TEST_P(ConvertColorToNV12Test, two_plane_missing_channel) {+ const auto rgb = std::make_shared<op::v0::Parameter>(element::f32, PartialShape::dynamic(4));+ this->op = this->make_op(rgb, false);++ this->input_shapes = StaticShapeVector{{5, 20, 20, 2}};+ OV_EXPECT_THROW(shape_inference(this->op.get(), this->input_shapes),+ NodeValidationFailure,+ HasSubstr("RGB/BGR input number of channels should be equal to 3"));+}++TYPED_TEST_P(ConvertColorToNV12Test, two_plane_height_not_div_by_2) {+ const auto rgb = std::make_shared<op::v0::Parameter>(element::f32, PartialShape::dynamic(4));+ this->op = this->make_op(rgb, false);++ this->input_shapes = StaticShapeVector{{5, 19, 20, 3}};+ OV_EXPECT_THROW(shape_inference(this->op.get(), this->input_shapes),+ NodeValidationFailure,+ HasSubstr("Image height must be even"));+}++TYPED_TEST_P(ConvertColorToNV12Test, two_plane_width_not_div_by_2) {+ const auto rgb = std::make_shared<op::v0::Parameter>(element::f32, PartialShape::dynamic(4));+ this->op = this->make_op(rgb, false);++ this->input_shapes = StaticShapeVector{{5, 20, 19, 3}};+ OV_EXPECT_THROW(shape_inference(this->op.get(), this->input_shapes),+ NodeValidationFailure,+ HasSubstr("Image width must be even"));+}++REGISTER_TYPED_TEST_SUITE_P(ConvertColorToNV12Test,+ single_plane_default,+ single_plane_explicit,+ two_plane,+ single_plane_dynamic_rank,+ single_plane_static_rank,+ two_plane_dynamic_rank,+ two_plane_static_rank,+ two_plane_missing_channel,+ two_plane_height_not_div_by_2,+ two_plane_width_not_div_by_2);++using ToNV12Types = testing::Types<op::v17::RGBtoNV12, op::v17::BGRtoNV12>;+INSTANTIATE_TYPED_TEST_SUITE_P(StaticShapeInference, ConvertColorToNV12Test, ToNV12Types);diff --git a/src/plugins/intel_cpu/tests/unit/sources.cmake b/src/plugins/intel_cpu/tests/unit/sources.cmakeindex 2c2ca0a5b04..14bb35c8868 100644--- a/src/plugins/intel_cpu/tests/unit/sources.cmake+++ b/src/plugins/intel_cpu/tests/unit/sources.cmake@@ -123,6 +123,7 @@ set(CPU_UNIT_TESTS_SRCS${CMAKE_CURRENT_LIST_DIR}/shape_inference_test/reshape_shape_inference_test.cpp${CMAKE_CURRENT_LIST_DIR}/shape_inference_test/reverse_sequence_shape_inference_test.cpp${CMAKE_CURRENT_LIST_DIR}/shape_inference_test/reverse_shape_inference_test.cpp+ ${CMAKE_CURRENT_LIST_DIR}/shape_inference_test/rgb_bgr_to_nv12_shape_inference_test.cpp${CMAKE_CURRENT_LIST_DIR}/shape_inference_test/rms_norm_shape_inference_test.cpp${CMAKE_CURRENT_LIST_DIR}/shape_inference_test/rnn_cell_shape_inference_test.cpp${CMAKE_CURRENT_LIST_DIR}/shape_inference_test/rnn_seq_shape_inference_test.cppdiff --git a/src/plugins/intel_gpu/tests/unit/test_cases/convert_color_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/convert_color_gpu_test.cppindex 031c416c729..b00db981b42 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/convert_color_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/convert_color_gpu_test.cpp@@ -2,6 +2,7 @@// SPDX-License-Identifier: Apache-2.0//+#include "openvino/reference/utils/convert_color_util.hpp"#include "test_utils.h"#include "random_generator.hpp"#include "opencl_helper_instance.hpp"@@ -32,26 +33,14 @@ void createReferenceDataNV12(const T* arg_y, const T* arg_uv, U* out_ptr,auto uv_index = (h / 2) * image_w + (w / 2) * 2;auto u_val = static_cast<float>(uv_ptr[uv_index]);auto v_val = static_cast<float>(uv_ptr[uv_index + 1]);- auto c = y_val - 16.f;- auto d = u_val - 128.f;- auto e = v_val - 128.f;- auto clip = [](float a) -> U {- if (std::is_integral<U>()) {- return static_cast<U>(std::min(std::max(std::round(a), 0.f), 255.f));- } else {- return static_cast<U>(std::min(std::max(a, 0.f), 255.f));- }- };- auto b = clip(1.164f * c + 2.018f * d);- auto g = clip(1.164f * c - 0.391f * d - 0.813f * e);- auto r = clip(1.164f * c + 1.596f * e);+ auto [r, g, b] = ov::reference::yuv_pixel_to_rgb<U>(y_val, u_val, v_val);if (to_rgb) {- out[y_index * 3] = r;+ out[y_index * 3] = r;out[y_index * 3 + 1] = g;out[y_index * 3 + 2] = b;} else {- out[y_index * 3] = b;+ out[y_index * 3] = b;out[y_index * 3 + 1] = g;out[y_index * 3 + 2] = r;}@@ -450,23 +439,6 @@ TEST(convert_color, nv12_to_rgb_single_plane_surface_u8) {checkStatus(clReleaseMemObject(nv12_image), "clReleaseMemObject");}-template <typename T>-std::tuple<T, T, T> yuv_pixel_to_rgb(float y_val, float u_val, float v_val) {- auto c = y_val - 16.f;- auto d = u_val - 128.f;- auto e = v_val - 128.f;- auto clip = [](float a) -> T {- if (std::is_integral<T>()) {- return static_cast<T>(std::min(std::max(std::round(a), 0.f), 255.f));- } else {- return static_cast<T>(std::min(std::max(a, 0.f), 255.f));- }- };- auto b = clip(1.164f * c + 2.018f * d);- auto g = clip(1.164f * c - 0.391f * d - 0.813f * e);- auto r = clip(1.164f * c + 1.596f * e);- return std::tuple<T, T, T>{r, g, b};-}template <typename T, typename U>void createReferenceDataI420(const T* arg_y, const T* arg_u, const T* arg_v, U* out_ptr,@@ -485,7 +457,7 @@ void createReferenceDataI420(const T* arg_y, const T* arg_u, const T* arg_v, U*auto u_val = static_cast<float>(u_ptr[uv_index]);auto v_val = static_cast<float>(v_ptr[uv_index]);- const auto& [r, g, b] = yuv_pixel_to_rgb<U>(y_val, u_val, v_val);+ const auto& [r, g, b] = ov::reference::yuv_pixel_to_rgb<U>(y_val, u_val, v_val);if (rgb_color_format) {out[y_index * 3] = r;out[y_index * 3 + 1] = g;diff --git a/src/tests/functional/base_func_tests/src/base/utils/generate_inputs.cpp b/src/tests/functional/base_func_tests/src/base/utils/generate_inputs.cppindex 7b5053485a8..fecff017c45 100644--- a/src/tests/functional/base_func_tests/src/base/utils/generate_inputs.cpp+++ b/src/tests/functional/base_func_tests/src/base/utils/generate_inputs.cpp@@ -1060,6 +1060,7 @@ const InputsMap& getInputMap() {#include "openvino/opsets/opset14_tbl.hpp"#include "openvino/opsets/opset15_tbl.hpp"#include "openvino/opsets/opset16_tbl.hpp"+#include "openvino/opsets/opset17_tbl.hpp"#include "ov_ops/opset_private_tbl.hpp"#undef _OPENVINO_OP_REGdiff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/convert_color_to_nv12.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/convert_color_to_nv12.hppnew file mode 100644index 00000000000..a01e2220f78--- /dev/null+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/convert_color_to_nv12.hpp@@ -0,0 +1,30 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <string>+#include <tuple>+#include <vector>++#include "shared_test_classes/base/ov_subgraph.hpp"++namespace ov {+namespace test {+using ConvertColorToNV12ParamsTuple = std::tuple<std::vector<InputShape>, // Input Shape+ ov::element::Type, // Element type+ bool, // Conversion type+ bool, // 1 or 2 planes+ std::string>; // Device name++class ConvertColorToNV12LayerTest : public testing::WithParamInterface<ConvertColorToNV12ParamsTuple>,+ virtual public ov::test::SubgraphBaseTest {+public:+ static std::string getTestCaseName(const testing::TestParamInfo<ConvertColorToNV12ParamsTuple>& obj);++protected:+ void SetUp() override;+};+} // namespace test+} // namespace ovdiff --git a/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_nv12.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_nv12.hppindex defdc765915..c8c927e154d 100644--- a/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_nv12.hpp+++ b/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_nv12.hpp@@ -11,5 +11,5 @@ namespace test {TEST_P(ConvertColorNV12LayerTest, Inference) {run();}-} // namespace test-} // namespace ov+} // namespace test+} // namespace ovdiff --git a/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_to_nv12.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_to_nv12.hppnew file mode 100644index 00000000000..838d42afb74--- /dev/null+++ b/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_to_nv12.hpp@@ -0,0 +1,15 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "shared_test_classes/single_op/convert_color_to_nv12.hpp"++namespace ov {+namespace test {+TEST_P(ConvertColorToNV12LayerTest, Inference) {+ run();+}+} // namespace test+} // namespace ovdiff --git a/src/tests/functional/plugin/shared/sources.cmake b/src/tests/functional/plugin/shared/sources.cmakeindex 96565dc8f73..e5b9c7601e2 100644--- a/src/tests/functional/plugin/shared/sources.cmake+++ b/src/tests/functional/plugin/shared/sources.cmake@@ -96,6 +96,7 @@ set(FUNC_SHARED_TESTS_SOURCES${CMAKE_CURRENT_LIST_DIR}/include/shared_test_classes/single_op/conversion.hpp${CMAKE_CURRENT_LIST_DIR}/include/shared_test_classes/single_op/convert_color_i420.hpp${CMAKE_CURRENT_LIST_DIR}/include/shared_test_classes/single_op/convert_color_nv12.hpp+ ${CMAKE_CURRENT_LIST_DIR}/include/shared_test_classes/single_op/convert_color_to_nv12.hpp${CMAKE_CURRENT_LIST_DIR}/include/shared_test_classes/single_op/convolution.hpp${CMAKE_CURRENT_LIST_DIR}/include/shared_test_classes/single_op/convolution_backprop_data.hpp${CMAKE_CURRENT_LIST_DIR}/include/shared_test_classes/single_op/ctc_greedy_decoder.hpp@@ -537,6 +538,7 @@ set(FUNC_SHARED_TESTS_SOURCES${CMAKE_CURRENT_LIST_DIR}/src/single_op/conversion.cpp${CMAKE_CURRENT_LIST_DIR}/src/single_op/convert_color_i420.cpp${CMAKE_CURRENT_LIST_DIR}/src/single_op/convert_color_nv12.cpp+ ${CMAKE_CURRENT_LIST_DIR}/src/single_op/convert_color_to_nv12.cpp${CMAKE_CURRENT_LIST_DIR}/src/single_op/convolution.cpp${CMAKE_CURRENT_LIST_DIR}/src/single_op/convolution_backprop_data.cpp${CMAKE_CURRENT_LIST_DIR}/src/single_op/ctc_greedy_decoder.cppdiff --git a/src/tests/functional/plugin/shared/src/single_op/convert_color_to_nv12.cpp b/src/tests/functional/plugin/shared/src/single_op/convert_color_to_nv12.cppnew file mode 100644index 00000000000..d6dc7ee97a4--- /dev/null+++ b/src/tests/functional/plugin/shared/src/single_op/convert_color_to_nv12.cpp@@ -0,0 +1,52 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "shared_test_classes/single_op/convert_color_to_nv12.hpp"++#include "openvino/op/bgr_to_nv12.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/rgb_to_nv12.hpp"++namespace ov {+namespace test {+std::string ConvertColorToNV12LayerTest::getTestCaseName(+ const testing::TestParamInfo<ConvertColorToNV12ParamsTuple>& obj) {+ const auto& [shapes, type, conversion, single_plane, device_name] = obj.param;+ std::ostringstream result;+ result << "IS=(";+ for (size_t i = 0lu; i < shapes.size(); i++) {+ result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : "");+ }+ result << ")_TS=";+ for (size_t i = 0lu; i < shapes.front().second.size(); i++) {+ result << "{";+ for (size_t j = 0lu; j < shapes.size(); j++) {+ result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : "");+ }+ result << "}_";+ }+ result << "modelType=" << type.c_type_string() << "_";+ result << "convRGB=" << conversion << "_";+ result << "single_plane=" << single_plane << "_";+ result << "targetDevice=" << device_name;+ return result.str();+}++void ConvertColorToNV12LayerTest::SetUp() {+ const auto& [shapes, net_type, conversionToRGB, single_plane, _targetDevice] = GetParam();+ targetDevice = _targetDevice;+ init_input_shapes(shapes);++ auto param = std::make_shared<ov::op::v0::Parameter>(net_type, inputDynamicShapes.front());++ std::shared_ptr<ov::Node> convert_color;+ if (conversionToRGB) {+ convert_color = std::make_shared<ov::op::v17::RGBtoNV12>(param, single_plane);+ } else {+ convert_color = std::make_shared<ov::op::v17::BGRtoNV12>(param, single_plane);+ }+ function = std::make_shared<ov::Model>(convert_color->outputs(), ov::ParameterVector{param}, "ConvertColorToNV12");+}+} // namespace test+} // namespace ov