tensoradapter.h 1.26 KB
Newer Older
1
/*!
2
 *  Copyright (c) 2020-2022 by Contributors
3
4
5
6
7
8
9
10
11
12
 * \file tensoradapter.h
 * \brief Header file for functions exposed by the adapter library.
 *
 * Functions in this library must be exported with extern "C" so that DGL can locate
 * them with dlsym(3) (or GetProcAddress on Windows).
 */

#ifndef TENSORADAPTER_H_
#define TENSORADAPTER_H_

13
14
15
#ifdef DGL_USE_CUDA
#include <cuda_runtime.h>
#endif  // DGL_USE_CUDA
16
17
18
19
20
21

namespace tensoradapter {

extern "C" {

/*!
22
23
 * \brief Allocate a piece of CPU memory via
 * PyTorch's CPUAllocator
24
 *
25
26
27
28
29
30
31
32
33
 * \param nbytes The size to be allocated.
 * \return Pointer to the allocated memory.
 */
void* CPURawAlloc(size_t nbytes);

/*!
 * \brief Free the CPU memory.
 *
 * \param ptr Pointer to the memory to be freed.
34
 */
35
void CPURawDelete(void* ptr);
36

37
38
39
40
41
42
#ifdef DGL_USE_CUDA
/*!
 * \brief Allocate a piece of GPU memory via
 * PyTorch's THCCachingAllocator.
 *
 * \param nbytes The size to be allocated.
43
 * \param stream The stream to be allocated on.
44
45
 * \return Pointer to the allocated memory.
 */
46
void* CUDARawAlloc(size_t nbytes, cudaStream_t stream);
47
48
49
50
51
52

/*!
 * \brief Free the GPU memory.
 *
 * \param ptr Pointer to the memory to be freed.
 */
53
void CUDARawDelete(void* ptr);
54
55
#endif  // DGL_USE_CUDA

56
57
58
59
60
}

};  // namespace tensoradapter

#endif  // TENSORADAPTER_H_