Unverified Commit 0d9a09df authored by pyynb's avatar pyynb Committed by GitHub
Browse files

[graphbolt] Disable liburing (#7366)

parent 658b2086
......@@ -20,6 +20,7 @@ dgl_option(BUILD_TYPE "Type of the build: dev, dogfood or release" "dev")
message(STATUS "Build for ${BUILD_TYPE}")
dgl_option(USE_CUDA "Build with CUDA" OFF)
dgl_option(USE_LIBURING "Build with liburing" OFF)
dgl_option(TORCH_PYTHON_INTERPS "Python interpreter for building sub-components" python3)
# Conda build related options.
......@@ -349,23 +350,26 @@ endif(EXTERNAL_PHMAP_PATH)
target_include_directories(dgl PRIVATE "tensoradapter/include")
target_include_directories(dgl PRIVATE "third_party/pcg/include")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
include(ExternalProject)
set(LIBURING_INSTALL_DIR ${CMAKE_BINARY_DIR}/third_party/liburing)
ExternalProject_Add(
liburing
SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/liburing
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=/
BUILD_COMMAND bash -c "make -j 4"
BUILD_IN_SOURCE ON
INSTALL_COMMAND make install DESTDIR=${LIBURING_INSTALL_DIR}
BUILD_BYPRODUCTS ${LIBURING_INSTALL_DIR}/lib/liburing.a
BUILD_BYPRODUCTS ${LIBURING_INSTALL_DIR}/include
DOWNLOAD_EXTRACT_TIMESTAMP true
)
set(LIBURING_INCLUDE ${LIBURING_INSTALL_DIR}/include)
set(LIBURING ${LIBURING_INSTALL_DIR}/lib/liburing.a)
endif()
if(USE_LIBURING)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-DHAVE_LIBRARY_LIBURING)
include(ExternalProject)
set(LIBURING_INSTALL_DIR ${CMAKE_BINARY_DIR}/third_party/liburing)
ExternalProject_Add(
liburing
SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/liburing
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=/
BUILD_COMMAND bash -c "make -j 4"
BUILD_IN_SOURCE ON
INSTALL_COMMAND make install DESTDIR=${LIBURING_INSTALL_DIR}
BUILD_BYPRODUCTS ${LIBURING_INSTALL_DIR}/lib/liburing.a
BUILD_BYPRODUCTS ${LIBURING_INSTALL_DIR}/include
DOWNLOAD_EXTRACT_TIMESTAMP true
)
set(LIBURING_INCLUDE ${LIBURING_INSTALL_DIR}/include)
set(LIBURING ${LIBURING_INSTALL_DIR}/lib/liburing.a)
endif()
endif(USE_LIBURING)
if(EXTERNAL_NANOFLANN_PATH)
include_directories(SYSTEM ${EXTERNAL_NANOFLANN_PATH})
......@@ -588,7 +592,9 @@ if(BUILD_GRAPHBOLT)
if(USE_CUDA)
add_dependencies(graphbolt gpu_cache)
endif(USE_CUDA)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_dependencies(graphbolt liburing)
endif()
if(USE_LIBURING)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_dependencies(graphbolt liburing)
endif()
endif(USE_LIBURING)
endif(BUILD_GRAPHBOLT)
......@@ -76,9 +76,11 @@ include_directories(BEFORE ${BOLT_DIR}
"../third_party/pcg/include")
target_link_libraries(${LIB_GRAPHBOLT_NAME} "${TORCH_LIBRARIES}")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_include_directories(${LIB_GRAPHBOLT_NAME} PRIVATE "../third_party/liburing/src/include")
get_filename_component(PARENT_DIR "${CMAKE_SOURCE_DIR}" DIRECTORY)
target_link_libraries(${LIB_GRAPHBOLT_NAME} ${PARENT_DIR}/build/third_party/liburing/lib/liburing.a)
if(USE_LIBURING)
target_include_directories(${LIB_GRAPHBOLT_NAME} PRIVATE "../third_party/liburing/src/include")
get_filename_component(PARENT_DIR "${CMAKE_SOURCE_DIR}" DIRECTORY)
target_link_libraries(${LIB_GRAPHBOLT_NAME} ${PARENT_DIR}/build/third_party/liburing/lib/liburing.a)
endif(USE_LIBURING)
endif()
if(USE_CUDA)
......
......@@ -20,7 +20,11 @@ static constexpr int kDiskAlignmentSize = 4096;
OnDiskNpyArray::OnDiskNpyArray(
std::string filename, torch::ScalarType dtype, torch::Tensor shape)
: filename_(filename), dtype_(dtype) {
#ifdef __linux__
#ifndef __linux__
throw std::runtime_error(
"OnDiskNpyArray is not supported on non-Linux systems.");
#endif
#ifdef HAVE_LIBRARY_LIBURING
ParseNumpyHeader(shape);
file_description_ = open(filename.c_str(), O_RDONLY | O_DIRECT);
if (file_description_ == -1) {
......@@ -35,7 +39,9 @@ OnDiskNpyArray::OnDiskNpyArray(
for (int64_t t = 0; t < num_thread_; t++) {
io_uring_queue_init(group_size_, &io_uring_queue_[t], 0);
}
#endif // __linux__
#else
throw std::runtime_error("DiskBasedFeature is not available now.");
#endif // HAVE_LIBRARY_LIBURING
}
c10::intrusive_ptr<OnDiskNpyArray> OnDiskNpyArray::Create(
......@@ -44,17 +50,17 @@ c10::intrusive_ptr<OnDiskNpyArray> OnDiskNpyArray::Create(
}
OnDiskNpyArray::~OnDiskNpyArray() {
#ifdef __linux__
#ifdef HAVE_LIBRARY_LIBURING
// IO queue exit.
for (int64_t t = 0; t < num_thread_; t++) {
io_uring_queue_exit(&io_uring_queue_[t]);
}
close(file_description_);
#endif // __linux__
#endif // HAVE_LIBRARY_LIBURING
}
void OnDiskNpyArray::ParseNumpyHeader(torch::Tensor shape) {
#ifdef __linux__
#ifdef HAVE_LIBRARY_LIBURING
// Parse numpy file header to get basic info of feature.
size_t word_size = c10::elementSize(dtype_);
int64_t num_dim = shape.numel();
......@@ -80,19 +86,19 @@ void OnDiskNpyArray::ParseNumpyHeader(torch::Tensor shape) {
// Get prefix length for computing feature offset,
// add one for new-line character.
prefix_len_ = header.size() + 1;
#endif // __linux__
#endif // HAVE_LIBRARY_LIBURING
}
torch::Tensor OnDiskNpyArray::IndexSelect(torch::Tensor index) {
#ifdef __linux__
#ifdef HAVE_LIBRARY_LIBURING
return IndexSelectIOUring(index);
#else
TORCH_CHECK(false, "OnDiskNpyArray is not supported on non-Linux systems.");
return torch::empty({0});
#endif // __linux__
#endif // HAVE_LIBRARY_LIBURING
}
#ifdef __linux__
#ifdef HAVE_LIBRARY_LIBURING
torch::Tensor OnDiskNpyArray::IndexSelectIOUring(torch::Tensor index) {
index = index.to(torch::kLong);
// The minimum page size to contain one feature.
......@@ -215,7 +221,6 @@ torch::Tensor OnDiskNpyArray::IndexSelectIOUring(torch::Tensor index) {
return result;
}
#endif // __linux__
#endif // HAVE_LIBRARY_LIBURING
} // namespace storage
} // namespace graphbolt
......@@ -9,10 +9,10 @@
#include <stdlib.h>
#include <torch/script.h>
#ifdef __linux__
#ifdef HAVE_LIBRARY_LIBURING
#include <liburing.h>
#include <unistd.h>
#endif
#endif // HAVE_LIBRARY_LIBURING
#include <cassert>
#include <cstdio>
......@@ -60,7 +60,7 @@ class OnDiskNpyArray : public torch::CustomClassHolder {
*/
torch::Tensor IndexSelect(torch::Tensor index);
#ifdef __linux__
#ifdef HAVE_LIBRARY_LIBURING
/**
* @brief Index-select operation on an on-disk numpy array using IO Uring for
* asynchronous I/O.
......@@ -76,8 +76,7 @@ class OnDiskNpyArray : public torch::CustomClassHolder {
* @throws std::runtime_error If index is out of range.
*/
torch::Tensor IndexSelectIOUring(torch::Tensor index);
#endif // __linux__
#endif // HAVE_LIBRARY_LIBURING
private:
std::string filename_; // Path to numpy file.
int file_description_; // File description.
......@@ -88,9 +87,9 @@ class OnDiskNpyArray : public torch::CustomClassHolder {
int num_thread_; // Default thread number.
int64_t group_size_ = 512; // Default group size.
#ifdef __linux__
#ifdef HAVE_LIBRARY_LIBURING
io_uring* io_uring_queue_; // io_uring queue.
#endif
#endif // HAVE_LIBRARY_LIBURING
};
} // namespace storage
......
......@@ -18,9 +18,8 @@ def to_on_disk_numpy(test_dir, name, t):
@unittest.skipIf(
sys.platform.startswith("win"),
reason="Tests for disk dataset can only deployed on Linux,"
"because the io_uring is only supportted by Linux kernel.",
True,
reason="DiskBasedFeature is not available now.",
)
def test_disk_based_feature():
with tempfile.TemporaryDirectory() as test_dir:
......@@ -85,6 +84,10 @@ def test_disk_based_feature():
reason="Tests for disk dataset can only deployed on Linux,"
"because the io_uring is only supportted by Linux kernel.",
)
@unittest.skipIf(
True,
reason="DiskBasedFeature is not available now.",
)
@pytest.mark.parametrize(
"dtype",
[
......@@ -129,6 +132,10 @@ def test_more_disk_based_feature(dtype, idtype, shape, index):
reason="Tests for large disk dataset can only deployed on Linux,"
"because the io_uring is only supportted by Linux kernel.",
)
@unittest.skipIf(
True,
reason="DiskBasedFeature is not available now.",
)
def test_disk_based_feature_repr():
with tempfile.TemporaryDirectory() as test_dir:
a = torch.tensor([[1, 2, 3], [4, 5, 6]])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment