github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/memutils/memory.h (about) 1 // Copyright (c) 2017-2018 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef MEMUTILS_MEMORY_H_ 16 #define MEMUTILS_MEMORY_H_ 17 18 #include <stddef.h> 19 #include <stdint.h> 20 #include "../cgoutils/utils.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 enum { 27 DEVICE_MEMORY_IMPLEMENTATION_FLAG = 1, 28 POOLED_MEMORY_FLAG = 1 << 1 29 }; 30 31 char NOT_SUPPORTED_ERR_MSG[] = "Not supported"; 32 33 // device_memory_flags_t & 0x1: HOST(0) or DEVICE(1) implementation 34 // device_memory_flags_t & 0x2: USE POOLED MEMORY MANAGEMENT OR NOT 35 typedef uint32_t DeviceMemoryFlags; 36 37 // We don't wrap the result with CGoCallResHandle as we know 38 // GetFlags is a safe call that will not throw any exceptions. 39 // Change to CGoCallResHandle when future it will throw any. 40 DeviceMemoryFlags GetFlags(); 41 42 CGoCallResHandle Init(); 43 44 CGoCallResHandle HostAlloc(size_t bytes); 45 46 CGoCallResHandle HostFree(void *p); 47 48 CGoCallResHandle CreateCudaStream(int device); 49 50 CGoCallResHandle WaitForCudaStream(void *s, int device); 51 52 CGoCallResHandle DestroyCudaStream(void *s, int device); 53 54 CGoCallResHandle DeviceAllocate(size_t bytes, int device); 55 56 CGoCallResHandle DeviceFree(void *p, int device); 57 58 CGoCallResHandle AsyncCopyHostToDevice( 59 void *dst, void *src, size_t bytes, void *stream, int device); 60 61 CGoCallResHandle AsyncCopyDeviceToDevice( 62 void *dst, void *src, size_t bytes, void *stream, int device); 63 64 CGoCallResHandle AsyncCopyDeviceToHost( 65 void *dst, void *src, size_t bytes, void *stream, int device); 66 67 CGoCallResHandle GetDeviceCount(); 68 69 CGoCallResHandle GetDeviceGlobalMemoryInMB(int device); 70 71 CGoCallResHandle CudaProfilerStart(); 72 73 CGoCallResHandle CudaProfilerStop(); 74 75 CGoCallResHandle GetDeviceMemoryInfo(size_t *freeSize, size_t *totalSize, 76 int device); 77 78 // All following functions are called by libalgorithm.so only, not intended 79 // to be exposed to go. Caller need to call cudaSetDevice before invocation. 80 CGoCallResHandle deviceMalloc(void **devPtr, size_t size); 81 CGoCallResHandle deviceFree(void *devPtr); 82 CGoCallResHandle deviceMemset(void *devPtr, int value, size_t count); 83 CGoCallResHandle asyncCopyHostToDevice(void *dst, const void *src, 84 size_t count, void *stream); 85 86 #ifdef __cplusplus 87 } 88 #endif 89 90 #endif // MEMUTILS_MEMORY_H_