LCOV - code coverage report
Current view: top level - capi-machine-learning-inference-1.8.8/c/src - ml-api-inference-internal.c (source / functions) Coverage Total Hit
Test: ML API 1.8.8-0 platform/core/api/machine-learning#e7fedae8956bcd2b3c627ecaa01984707296bbdb Lines: 0.0 % 40 0
Test Date: 2026-04-30 21:49:05 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /* SPDX-License-Identifier: Apache-2.0 */
       2              : /**
       3              :  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved.
       4              :  *
       5              :  * @file ml-api-inference-internal.c
       6              :  * @date 19 October 2021
       7              :  * @brief ML-API Internal Utility Functions for inference implementations
       8              :  * @see https://github.com/nnstreamer/api
       9              :  * @author MyungJoo Ham <myungjoo.ham@samsung.com>
      10              :  * @bug No known bugs except for NYI items
      11              :  */
      12              : 
      13              : #include <string.h>
      14              : 
      15              : #include <nnstreamer_plugin_api_util.h>
      16              : #include <tensor_typedef.h>
      17              : #include "ml-api-inference-internal.h"
      18              : #include "ml-api-internal.h"
      19              : 
      20              : /**
      21              :  * @brief Check tensor-info has extended rank value.
      22              :  */
      23              : static gboolean
      24            0 : gst_info_is_extended (const GstTensorsInfo * gst_info)
      25              : {
      26              :   GstTensorInfo *_info;
      27              :   guint i;
      28              : 
      29            0 :   for (i = 0; i < gst_info->num_tensors; i++) {
      30            0 :     _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) gst_info, i);
      31            0 :     if (!_info)
      32            0 :       _ml_error_report_return (FALSE,
      33              :           "The parameter, gst_info, has invalid number of tensors. The max number of tensors is "
      34              :           NNS_TENSOR_SIZE_LIMIT_STR);
      35              : 
      36            0 :     if (_info->dimension[ML_TENSOR_RANK_LIMIT_PREV] > 0)
      37            0 :       return TRUE;
      38              :   }
      39              : 
      40            0 :   return FALSE;
      41              : }
      42              : 
      43              : /**
      44              :  * @brief Allocates a tensors information handle from gst info.
      45              :  */
      46              : int
      47            0 : _ml_tensors_info_create_from_gst (ml_tensors_info_h * ml_info,
      48              :     const GstTensorsInfo * gst_info)
      49              : {
      50              :   gboolean is_extended;
      51              : 
      52            0 :   if (!ml_info)
      53            0 :     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
      54              :         "The parameter, ml_info, is NULL. It should be a valid ml_tensors_info_h instance usually created by ml_tensors_info_create(). This could be an internal bug of ML API.");
      55              : 
      56            0 :   if (!gst_info)
      57            0 :     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
      58              :         "The parameter, gst_info, is NULL. It should be a valid GstTensorsInfo instance. This could be an internal bug of ML API.");
      59              : 
      60            0 :   is_extended = gst_info_is_extended (gst_info);
      61            0 :   if (is_extended)
      62            0 :     _ml_error_report_return_continue_iferr
      63              :         (ml_tensors_info_create_extended (ml_info),
      64              :         "The call to ml_tensors_info_create_extended has failed with %d.",
      65              :         _ERRNO);
      66              :   else
      67            0 :     _ml_error_report_return_continue_iferr (ml_tensors_info_create (ml_info),
      68              :         "The call to ml_tensors_info_create has failed with %d.", _ERRNO);
      69              : 
      70            0 :   _ml_tensors_info_copy_from_gst (*ml_info, gst_info);
      71            0 :   return ML_ERROR_NONE;
      72              : }
      73              : 
      74              : /**
      75              :  * @brief Copies tensor meta info from gst tensors info.
      76              :  * @bug Thread safety required. Check its internal users first!
      77              :  */
      78              : int
      79            0 : _ml_tensors_info_copy_from_gst (ml_tensors_info_h ml_info,
      80              :     const GstTensorsInfo * gst_info)
      81              : {
      82              :   ml_tensors_info_s *_info;
      83              : 
      84            0 :   if (!ml_info)
      85            0 :     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
      86              :         "The parameter, ml_info, is NULL. It should be a valid ml_tensors_info_s instance, usually created by ml_tensors_info_create(). This is probably an internal bug of ML API.");
      87            0 :   if (!gst_info)
      88            0 :     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
      89              :         "The parameter, gst_info, is NULL. It should be a valid GstTensorsInfo instance. This is probably an internal bug of ML API.");
      90              : 
      91            0 :   _info = (ml_tensors_info_s *) ml_info;
      92              : 
      93            0 :   G_LOCK_UNLESS_NOLOCK (*_info);
      94            0 :   _info->is_extended = gst_info_is_extended (gst_info);
      95            0 :   gst_tensors_info_copy (&_info->info, gst_info);
      96            0 :   G_UNLOCK_UNLESS_NOLOCK (*_info);
      97              : 
      98            0 :   return ML_ERROR_NONE;
      99              : }
     100              : 
     101              : /**
     102              :  * @brief Copies tensor meta info from gst tensors info.
     103              :  * @bug Thread safety required. Check its internal users first!
     104              :  */
     105              : int
     106            0 : _ml_tensors_info_copy_from_ml (GstTensorsInfo * gst_info,
     107              :     const ml_tensors_info_h ml_info)
     108              : {
     109              :   ml_tensors_info_s *_info;
     110              : 
     111            0 :   if (!ml_info)
     112            0 :     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
     113              :         "The parameter, ml_info, is NULL. It should be a valid ml_tensors_info_s instance, usually created by ml_tensors_info_create(). This is probably an internal bug of ML API.");
     114            0 :   if (!gst_info)
     115            0 :     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
     116              :         "The parameter, gst_info, is NULL. It should be a valid GstTensorsInfo instance. This is probably an internal bug of ML API.");
     117              : 
     118            0 :   _info = (ml_tensors_info_s *) ml_info;
     119              : 
     120            0 :   G_LOCK_UNLESS_NOLOCK (*_info);
     121            0 :   gst_tensors_info_copy (gst_info, &_info->info);
     122            0 :   G_UNLOCK_UNLESS_NOLOCK (*_info);
     123              : 
     124            0 :   return ML_ERROR_NONE;
     125              : }
        

Generated by: LCOV version 2.4-0