tensoradapter.h 1.08 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*!
 *  Copyright (c) 2020 by Contributors
 * \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_

#include <dlpack/dlpack.h>
#include <vector>

namespace tensoradapter {

extern "C" {

/*!
21
 * \brief Allocate an empty tensor.
22
23
24
25
26
27
 *
 * \param shape The shape
 * \param dtype The data type
 * \param ctx The device
 * \return The allocated tensor
 */
28
DLManagedTensor* TAempty(
29
30
    std::vector<int64_t> shape, DLDataType dtype, DLContext ctx);

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifdef DGL_USE_CUDA
/*!
 * \brief Allocate a piece of GPU memory via
 * PyTorch's THCCachingAllocator.
 *
 * \param nbytes The size to be allocated.
 * \return Pointer to the allocated memory.
 */
void* RawAlloc(size_t nbytes);

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

49
50
51
52
53
}

};  // namespace tensoradapter

#endif  // TENSORADAPTER_H_