NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
ScriptEngineUtils.h
Go to the documentation of this file.
1 /*
2 * SPDX-FileCopyrightText: Copyright (c) 2020-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: MIT
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23 
25 
26 #ifndef NVNEURAL_SCRIPTENGINEUTILS_H
27 #define NVNEURAL_SCRIPTENGINEUTILS_H
28 
29 #include <algorithm>
30 #include <string>
31 #include <vector>
32 
33 namespace nvneural {
34 namespace detail {
35 
36 template <class T>
37 int indexOf(const std::vector<T>& values, const T& name)
38 {
39  const size_t pos = size_t(std::find(values.begin(), values.end(), name) - values.begin());
40  if (pos >= values.size())
41  {
42  return -1;
43  }
44  else
45  {
46  return int(pos);
47  }
48 }
49 
50 std::string trim(const std::string& s);
51 std::vector<std::string> split(const std::string& strToSplit, char delimeter, bool skipEmpty);
52 std::string join(const std::vector<std::string>& arr, const std::string& delimiter);
53 
54 std::vector<uint8_t> fromHex(const std::string& hex);
55 
56 std::string restyleLayerName(const std::string& name);
57 
58 float convertStringToFloat(const std::string& str, const float def_value = 0.0f);
59 
60 unsigned int roundUp(unsigned int nominator, unsigned int denominator);
61 
62 struct SizeValue
63 {
64  size_t x = 1, y = 1, z = 1;
65  SizeValue()
66  {
67  }
68 
69  explicit SizeValue(const SizeValue& v);
70  explicit SizeValue(size_t _x, size_t _y = 1, size_t _z = 1);
71  explicit SizeValue(const std::string& value);
72 
73  size_t size();
74 
75  bool fromString(const std::string& v, size_t fill = 1);
76  bool operator==(const SizeValue& val) const;
77  bool operator!=(const SizeValue& val) const;
78 
79  std::string toString() const;
80 
81 private:
82 
83  int toInt(const std::string& v);
84 };
85 
86 } // namespace detail
87 } // namespace nvneural
88 
89 #endif // !NVNEURAL_SCRIPTENGINEUTILS_H
std::vector< std::string > split(std::string strToSplit, char delimiter, bool skip_empty=false)
Splits a string by a delimiter, returns a vector of the split strings.
Definition: CoreHelpers.h:155