LCOV - code coverage report
Current view: top level - capi-machine-learning-inference-1.8.6/c/src - ml-api-inference-internal.c (source / functions) Coverage Total Hit
Test: ML API 1.8.6-0 nnstreamer/api#7f8530c294f86ec880b29347a861499239d358a1 Lines: 97.5 % 40 39
Test Date: 2025-06-06 05:24:38 Functions: 100.0 % 4 4

            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        25796 : gst_info_is_extended (const GstTensorsInfo * gst_info)
      25              : {
      26              :   GstTensorInfo *_info;
      27              :   guint i;
      28              : 
      29        52894 :   for (i = 0; i < gst_info->num_tensors; i++) {
      30        27122 :     _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) gst_info, i);
      31        27122 :     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        27122 :     if (_info->dimension[ML_TENSOR_RANK_LIMIT_PREV] > 0)
      37           24 :       return TRUE;
      38              :   }
      39              : 
      40        25772 :   return FALSE;
      41              : }
      42              : 
      43              : /**
      44              :  * @brief Allocates a tensors information handle from gst info.
      45              :  */
      46              : int
      47        12876 : _ml_tensors_info_create_from_gst (ml_tensors_info_h * ml_info,
      48              :     const GstTensorsInfo * gst_info)
      49              : {
      50              :   gboolean is_extended;
      51              : 
      52        12876 :   if (!ml_info)
      53            1 :     _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        12875 :   if (!gst_info)
      57            1 :     _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        12874 :   is_extended = gst_info_is_extended (gst_info);
      61        12874 :   if (is_extended)
      62            7 :     _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        12867 :     _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        12874 :   _ml_tensors_info_copy_from_gst (*ml_info, gst_info);
      71        12874 :   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        12924 : _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        12924 :   if (!ml_info)
      85            1 :     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
      86              :         "The parmater, 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        12923 :   if (!gst_info)
      88            1 :     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
      89              :         "The parmater, gst_info, is NULL. It should be a valid GstTensorsInfo instance. This is probably an internal bug of ML API.");
      90              : 
      91        12922 :   _info = (ml_tensors_info_s *) ml_info;
      92              : 
      93        12922 :   G_LOCK_UNLESS_NOLOCK (*_info);
      94        12922 :   _info->is_extended = gst_info_is_extended (gst_info);
      95        12922 :   gst_tensors_info_copy (&_info->info, gst_info);
      96        12922 :   G_UNLOCK_UNLESS_NOLOCK (*_info);
      97              : 
      98        12922 :   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         6426 : _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         6426 :   if (!ml_info)
     112            1 :     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
     113              :         "The parmater, 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         6425 :   if (!gst_info)
     115            1 :     _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
     116              :         "The parmater, gst_info, is NULL. It should be a valid GstTensorsInfo instance. This is probably an internal bug of ML API.");
     117              : 
     118         6424 :   _info = (ml_tensors_info_s *) ml_info;
     119              : 
     120         6424 :   G_LOCK_UNLESS_NOLOCK (*_info);
     121         6424 :   gst_tensors_info_copy (gst_info, &_info->info);
     122         6424 :   G_UNLOCK_UNLESS_NOLOCK (*_info);
     123              : 
     124         6424 :   return ML_ERROR_NONE;
     125              : }
        

Generated by: LCOV version 2.0-1