Skip to content

Commit 38c9260

Browse files
committed
update build instrucion
1 parent 355a9a6 commit 38c9260

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

CMakeLists.txt

+9-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ project(tfdlpack C CXX)
44

55
add_definitions(-std=c++11 -fPIC)
66
include(cmake/util/FindCUDA.cmake)
7-
option(NO_CUDA "Only build TFDLPACK with cpu" OFF)
7+
8+
option(USE_CUDA "Build TF-DLPACK with CUDA support" ON)
89

910
if(NOT PYTHON_EXECUTABLE)
1011
execute_process(
@@ -35,12 +36,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 ${TF_CFLAGS}")
3536
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -D_GLIBCXX_USE_CXX11_ABI=0 ${TF_CFLAGS}")
3637
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3 -ggdb -D_GLIBCXX_USE_CXX11_ABI=0 ${TF_CFLAGS}")
3738

38-
if (NOT NO_CUDA)
39+
if (USE_CUDA)
40+
message(STATUS "Build with CUDA.")
3941
add_definitions(-DTFDLPACK_USE_CUDA)
4042
find_cuda(ON REQUIRED)
4143
if(NOT CUDA_FOUND)
4244
message(FATAL_ERROR "Cannot find CUDA.")
4345
endif()
46+
else()
47+
message(STATUS "Build without CUDA.")
4448
endif()
4549

4650
include_directories(third_party/dlpack/include)
@@ -49,10 +53,10 @@ file(GLOB SRC
4953
src/*.cc
5054
)
5155

52-
if (NO_CUDA)
53-
add_library(tfdlpack SHARED ${SRC})
54-
else()
56+
if (USE_CUDA)
5557
cuda_add_library(tfdlpack SHARED ${SRC})
58+
else()
59+
add_library(tfdlpack SHARED ${SRC})
5660
endif()
5761

5862
target_link_libraries(tfdlpack ${TF_LFLAGS})

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ Build
3636
```
3737
mkdir build
3838
cd build
39-
cmake ..
39+
cmake .. # To build without CUDA, add -DUSE_CUDA=OFF
4040
make -j4
4141
```
4242

43-
so file path is now fixed in `python/tfdlpack/__init__.py`
44-
Need to change manually
43+
Export the library path:
44+
```bash
45+
export TF_DLPACK_LIBRARY_PATH=/path/to/tf-dlpack/repo/build
46+
```
4547

46-
And export the python path to `import tfdlpack`
48+
Export python path to `import tfdlpack`
4749
```bash
48-
export PYTHONPATH=/home/ubuntu/dev/tfdlpack/python/:${PYTHONPATH}
50+
export PYTHONPATH=/path/to/tf-dlpack/repo/python/:${PYTHONPATH}
4951
```
5052

5153
## License

python/tfdlpack/core.py

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# version number
1111
__version__ = libinfo.__version__
1212

13-
# print(libinfo.find_lib_path()[0])
1413
dlpack_ops = load_library.load_op_library(libinfo.find_lib_path()[0])
1514
_to_dlpack_address = dlpack_ops.to_dlpack
1615
_from_dlpack = dlpack_ops.from_dlpack

src/from_dlpack_kernel.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ inline bool IsAligned(size_t alignment, void *data_ptr) {
2525

2626
class DLPackAllocator : public Allocator {
2727
public:
28-
static constexpr size_t kAllocatorAlignment = 64;
29-
3028
explicit DLPackAllocator(DLManagedTensor *dlm_tensor) {
3129
dlm_tensor_ = dlm_tensor;
3230
data_ = dlm_tensor->dl_tensor.data;
3331

3432
// Shape
3533
shape_ = TensorShape();
36-
int ndim = dlm_tensor->dl_tensor.ndim;
37-
int64_t *shape = dlm_tensor->dl_tensor.shape;
34+
const int ndim = dlm_tensor->dl_tensor.ndim;
35+
const int64_t *shape = dlm_tensor->dl_tensor.shape;
3836
for (int i = 0; i < ndim; i++) {
3937
shape_.AddDim(shape[i]);
4038
}
@@ -61,7 +59,6 @@ class DLPackAllocator : public Allocator {
6159
void DeallocateRaw(void *ptr) {
6260
// This would lead to double free, haven't figure out the problem
6361
dlm_tensor_->deleter(const_cast<DLManagedTensor *>(dlm_tensor_));
64-
// std::cout << "Deconstruct dlpack tensor" << std::endl;
6562
delete this;
6663
}
6764

@@ -78,6 +75,8 @@ class DLPackAllocator : public Allocator {
7875
int64 num_elements_;
7976
TensorShape shape_;
8077
Status allocation_status_;
78+
79+
TF_DISALLOW_COPY_AND_ASSIGN(DLPackAllocator);
8180
};
8281

8382
class FromDLPackOP : public OpKernel {

tests/test_zero_copy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import torch as th
33
from torch.utils.dlpack import from_dlpack, to_dlpack
44
from tfdlpack import from_dlpack as tf_from_dlpack
5-
import gpustat
65
import pytest
76

87
def get_gpu_memory_used():
8+
import gpustat
99
gpu_query = gpustat.GPUStatCollection.new_query()
1010
gmem_used = gpu_query[0].memory_used
1111
return gmem_used
@@ -28,4 +28,4 @@ def test_zero_copy():
2828
print(m3)
2929

3030
if __name__ == "__main__":
31-
test_zero_copy()
31+
test_zero_copy()

0 commit comments

Comments
 (0)