NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
ZlibResourceDictionary.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_ZLIBRESOURCEDICTIONARY_H
27 #define NVNEURAL_ZLIBRESOURCEDICTIONARY_H
28 
29 #include <nvneural/CodeGenTypes.h>
30 #include <nvneural/RefObject.h>
31 #include <initializer_list>
32 #include <map>
33 #include <vector>
34 
35 namespace nvneural {
36 
40 class ZlibResourceDictionary : public refobj::RefObjectBase<refobj::Implements<IResourceDictionary>>
41 {
42 public:
44  using ByteVector = std::vector<std::uint8_t>;
46  using ResourceMap = std::map<IResourceDictionary::ResourceId, ByteVector>;
47 
53  explicit ZlibResourceDictionary(const ResourceMap& resourcePairs);
54 
58  const void** ppBufferOut,
59  std::size_t* pBufferSizeOut) const noexcept override;
60 
61 private:
62  ResourceMap m_resources;
63 
64  void uncompressResources(const ResourceMap& resourcePairs);
65 };
66 
67 } // namespace nvneural
68 
69 #endif // NVNEURAL_ZLIBRESOURCEDICTIONARY_H
Definitions of C++ code generation interfaces exported by tools and plugins.
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:275
Standard implementation for IRefObject-derived objects.
std::uint32_t ResourceId
Unique identifier for a resource.
Definition: CodeGenTypes.h:41
Resource dictionary that decompresses payloads using Zlib.
Definition: ZlibResourceDictionary.h:41
std::vector< std::uint8_t > ByteVector
Convenience typedef representing a vector of bytes.
Definition: ZlibResourceDictionary.h:44
std::map< IResourceDictionary::ResourceId, ByteVector > ResourceMap
Convenience typedef representing an associative array mapping resource IDs to ByteVector buffers.
Definition: ZlibResourceDictionary.h:46
ZlibResourceDictionary(const ResourceMap &resourcePairs)
Creates a ZlibResourceDictionary allowing unpacking of the provided resource map.
Definition: ZlibResourceDictionary.cpp:30
NeuralResult getResource(IResourceDictionary::ResourceId resourceId, const void **ppBufferOut, std::size_t *pBufferSizeOut) const noexcept
Retrieves a buffer that was stored in this dictionary.
Definition: ZlibResourceDictionary.cpp:35
Parameterized base class implementing common IRefObject operations.
Definition: RefObject.h:336