NVIDIA NvNeural SDK  2021.1
GPU inference framework for NVIDIA Nsight Deep Learning Designer
CudaTypes.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_CUDATYPES_H
27 #define NVNEURAL_CUDATYPES_H
28 
29 #include <nvneural/CoreTypes.h>
30 #include <cuda.h>
31 
32 namespace nvneural {
33 
34 class INetworkBackendCuda;
36 #define NVNEURAL_INETWORKBACKENDCUDA_OBJECTCLASS "com.nvidia.backendcuda"
38 #define NVNEURAL_ICUDAMEMORYALLOCATOR_OBJECTCLASS "com.nvidia.memoryallocatorcuda"
39 
52 {
53 public:
55  static const IRefObject::TypeId typeID = 0x121e6098096e5c97ul;
56 
64  virtual NeuralResult allocateMemoryBlock(MemoryHandle* pHandleOut, std::size_t byteCount, MemorySemantic semantic) noexcept = 0;
65 
72  virtual NeuralResult freeMemoryBlock(MemoryHandle handle) noexcept = 0;
73 
78  virtual void* getAddressForMemoryBlock(MemoryHandle handle) const noexcept = 0;
79 
89  virtual std::size_t getSizeForMemoryBlock(MemoryHandle handle) const noexcept = 0;
90 
104  virtual NeuralResult lockMemoryBlock(MemoryHandle handle) noexcept = 0;
105 
115  virtual NeuralResult unlockMemoryBlock(MemoryHandle handle) noexcept = 0;
116 
127  virtual NeuralResult compactMemory() noexcept = 0;
128 };
129 
132 {
133 public:
135  static const IRefObject::TypeId typeID = 0x467d6d0e91bcc332ul;
136 
151  INetworkBackendCuda* pBackend,
152  std::size_t gridSizeX,
153  std::size_t gridSizeY,
154  std::size_t gridSizeZ,
155  std::size_t blockSizeX,
156  std::size_t blockSizeY,
157  std::size_t blockSizeZ,
158  void** ppArguments,
159  std::uint32_t smem) const noexcept = 0;
160 
165  virtual CUmodule module() const noexcept = 0;
166 
171  virtual CUfunction function() const noexcept = 0;
172 
177  virtual std::size_t compiledBinarySize() const noexcept = 0;
178 
183  virtual const void* compiledBinary() const noexcept = 0;
184 };
185 
191 {
192 public:
194  static const IRefObject::TypeId typeID = 0xe39c2816f916d342ul;
195 
198  {
200  const char* pModuleName = nullptr;
202  const char* pModuleSource = nullptr;
204  const char* pModuleEntryPoint = nullptr;
207  IStringList* pHeaderNames = nullptr;
212  IStringList* pHeaderContents = nullptr;
215  IStringList* pAdditionalCompilerOptions = nullptr;
216  };
217 
221  virtual const char* targetArchitecture() const noexcept = 0;
222 
238  virtual NeuralResult setTargetArchitecture(const char* pTargetArch) noexcept = 0;
239 
247  virtual NeuralResult compile(ICudaCompiledFunction** ppCompiledFunctionOut, const CompilationDetails& compilationDetails) noexcept = 0;
248 
255  virtual NeuralResult loadCubin(ICudaCompiledFunction** ppCompiledFunctionOut, std::uint8_t* pCode, std::size_t codeSize, const char* pEntryPoint) noexcept = 0;
256 };
257 
267 {
268 public:
270  static const IRefObject::TypeId typeID = 0x61f19c57a3032f9ul;
271 
273  virtual ICudaMemoryAllocator* getAllocator() const noexcept = 0;
274 
278  virtual NeuralResult setAllocator(ICudaMemoryAllocator* pAllocator) noexcept = 0;
279 
281  virtual CUcontext getCudaContext() const noexcept = 0;
282 
284  virtual CUdevice getCudaDevice() const noexcept = 0;
285 
290  virtual CUstream getCudaStream() const noexcept = 0;
291 
293  virtual ICudaRuntimeCompiler* runtimeCompiler() const noexcept = 0;
294 };
295 
296 } // namespace nvneural
297 
298 #endif // NVNEURAL_CUDATYPES_H
Fundamental NvNeural data types are declared here.
MemorySemantic
Describes the intended purpose of allocated GPU memory.
Definition: CoreTypes.h:629
MemoryHandle__type * MemoryHandle
Opaque typedef used to represent INetworkBackend memory handles.
Definition: CoreTypes.h:624
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:273
Represents a runtime-compiled function object from ICudaRuntimeCompiler.
Definition: CudaTypes.h:132
virtual CUmodule module() const noexcept=0
Returns the CUmodule containing this function object.
virtual NeuralResult launch(INetworkBackendCuda *pBackend, std::size_t gridSizeX, std::size_t gridSizeY, std::size_t gridSizeZ, std::size_t blockSizeX, std::size_t blockSizeY, std::size_t blockSizeZ, void **ppArguments, std::uint32_t smem) const noexcept=0
Launches the function on the specified CUDA backend's stream.
Generic interface for CUDA device memory allocation.
Definition: CudaTypes.h:52
static const IRefObject::TypeId typeID
Interface TypeId for InterfaceOf purposes.
Definition: CudaTypes.h:55
virtual NeuralResult unlockMemoryBlock(MemoryHandle handle) noexcept=0
Removes a lock from a preexisting memory block.
virtual std::size_t getSizeForMemoryBlock(MemoryHandle handle) const noexcept=0
Returns the buffer size associated with a memory handle.
virtual NeuralResult compactMemory() noexcept=0
Signals the allocator to release unused memory blocks back to the system.
virtual void * getAddressForMemoryBlock(MemoryHandle handle) const noexcept=0
Converts a memory handle to a GPU virtual address.
virtual NeuralResult lockMemoryBlock(MemoryHandle handle) noexcept=0
Adds a lock to a preexisting memory block.
virtual NeuralResult freeMemoryBlock(MemoryHandle handle) noexcept=0
Frees a memory block.
virtual NeuralResult allocateMemoryBlock(MemoryHandle *pHandleOut, std::size_t byteCount, MemorySemantic semantic) noexcept=0
Allocates a new memory block and returns a handle to it.
Represents a runtime compiler that can transform CUDA source code into compiled functions.
Definition: CudaTypes.h:191
virtual const char * targetArchitecture() const noexcept=0
Returns the current target GPU architecture for compilation.
INetworkBackend companion interface with CUDA-specific functionality.
Definition: CudaTypes.h:267
virtual ICudaMemoryAllocator * getAllocator() const noexcept=0
Returns the CUDA memory allocator interface.
Base class for all objects, similar to COM's IUnknown.
Definition: CoreTypes.h:341
std::uint64_t TypeId
Every interface must define a unique TypeId. This should be randomized.
Definition: CoreTypes.h:347
IStringList represents an immutable collection of strings.
Definition: CoreTypes.h:946
Params struct describing a compilation request.
Definition: CudaTypes.h:198