Skip to content

Commit

Permalink
Update CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
cbalioglu committed Dec 6, 2023
1 parent ca2ac55 commit 3f60fd7
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 46 deletions.
13 changes: 13 additions & 0 deletions fairseq2n/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ option(FAIRSEQ2N_USE_CUDA
OFF
)

option(FAIRSEQ2N_SUPPORT_IMAGE
#DESCRIPTION
"Supports JPEG/PNG decoding."
#VALUE
ON
)

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(default_thread_lib tbb)
else()
Expand Down Expand Up @@ -160,6 +167,12 @@ find_package(SndFile 1.0.25 REQUIRED)

find_package(Threads REQUIRED)

if(FAIRSEQ2N_SUPPORT_IMAGE)
find_package(JPEG REQUIRED)

find_package(PNG REQUIRED)
endif()

if(FAIRSEQ2N_THREAD_LIB STREQUAL "tbb")
find_package(TBB 2021.8 REQUIRED)
endif()
Expand Down
5 changes: 5 additions & 0 deletions fairseq2n/cmake/summary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function(fairseq2n_print_project_summary)
message(STATUS " CUDA NVCC : ${CUDAToolkit_NVCC_EXECUTABLE}")
message(STATUS " CUDA Architectures : ${CMAKE_CUDA_ARCHITECTURES}")
endif()
message(STATUS " FAIRSEQ2N_SUPPORT_IMAGE : ${FAIRSEQ2N_SUPPORT_IMAGE}")
message(STATUS " FAIRSEQ2N_BUILD_PYTHON_BINDINGS : ${FAIRSEQ2N_BUILD_PYTHON_BINDINGS}")
if(FAIRSEQ2N_BUILD_PYTHON_BINDINGS)
message(STATUS " FAIRSEQ2N_PYTHON_DEVEL : ${FAIRSEQ2N_PYTHON_DEVEL}")
Expand All @@ -50,6 +51,10 @@ function(fairseq2n_print_project_summary)
if(FAIRSEQ2N_THREAD_LIB STREQUAL "tbb")
message(STATUS " Intel oneTBB : ${TBB_VERSION}")
endif()
if(FAIRSEQ2N_SUPPORT_IMAGE)
message(STATUS " libjpeg : ${JPEG_VERSION}")
message(STATUS " libpng : ${PNG_VERSION_STRING}")
endif()
message(STATUS " libsndfile : ${SndFile_VERSION}")
message(STATUS "")
endfunction()
7 changes: 7 additions & 0 deletions fairseq2n/python/src/fairseq2n/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ def supports_cuda() -> bool:
return _supports_cuda() # type: ignore[no-any-return]


def supports_image() -> bool:
"""Return ``True`` if fairseq2n supports JPEG/PNG decoding."""
from fairseq2n.bindings import _supports_image # type: ignore[attr-defined]

return _supports_image() # type: ignore[no-any-return]


def cuda_version() -> Optional[Tuple[int, int]]:
"""Return the version of CUDA that fairseq2n supports.
Expand Down
2 changes: 1 addition & 1 deletion fairseq2n/python/src/fairseq2n/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ target_sources(py_bindings
init.cc
memory.cc
data/audio.cc
data/image.cc
data/data_pipeline.cc
data/init.cc
data/image.cc
data/string.cc
data/text/converters.cc
data/text/init.cc
Expand Down
7 changes: 7 additions & 0 deletions fairseq2n/python/src/fairseq2n/bindings/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ PYBIND11_MODULE(bindings, m)
return supports_cuda;
});

m.def(
"_supports_image",
[]
{
return supports_image;
});

// See https://github.com/llvm/llvm-project/issues/57123.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code-return"
Expand Down
30 changes: 19 additions & 11 deletions fairseq2n/src/fairseq2n/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ target_sources(fairseq2n
data/detail/file.cc
data/detail/file_system.cc
data/image/image_decoder.cc
data/image/detail/jpeg_decompress_struct.cc
data/image/detail/png_read_struct.cc
data/text/string_splitter.cc
data/text/string_to_int_converter.cc
data/text/string_to_tensor_converter.cc
Expand All @@ -72,6 +70,14 @@ target_sources(fairseq2n
data/text/sentencepiece/sp_processor.cc
)

if(FAIRSEQ2N_SUPPORT_IMAGE)
target_sources(fairseq2n
PRIVATE
data/image/detail/jpeg_decompress_struct.cc
data/image/detail/png_read_struct.cc
)
endif()

if(FAIRSEQ2N_USE_CUDA)
target_sources(fairseq2n
PRIVATE
Expand All @@ -87,6 +93,10 @@ if(FAIRSEQ2N_THREAD_LIB STREQUAL "tbb")
target_compile_definitions(fairseq2n PRIVATE FAIRSEQ2N_USE_TBB)
endif()

if(FAIRSEQ2N_SUPPORT_IMAGE)
target_compile_definitions(fairseq2n PRIVATE FAIRSEQ2N_SUPPORT_IMAGE)
endif()

if(FAIRSEQ2N_USE_CUDA)
target_compile_features(fairseq2n PRIVATE cuda_std_17)

Expand All @@ -105,23 +115,18 @@ target_include_directories(fairseq2n ${system}
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>
)

find_package(PNG REQUIRED)
find_package(JPEG REQUIRED)

target_link_libraries(fairseq2n
PRIVATE
${CMAKE_DL_LIBS}
PRIVATE
fmt::fmt
Iconv::Iconv
SndFile::sndfile
Threads::Threads
fmt::fmt
kaldi-native-fbank::core
kuba-zip
natsort
Threads::Threads
sentencepiece-static
SndFile::sndfile
PNG::PNG
JPEG::JPEG
PUBLIC
torch
)
Expand All @@ -130,11 +135,14 @@ if(FAIRSEQ2N_THREAD_LIB STREQUAL "tbb")
target_link_libraries(fairseq2n PRIVATE TBB::tbb)
endif()

if(FAIRSEQ2N_SUPPORT_IMAGE)
target_link_libraries(fairseq2n PRIVATE JPEG::JPEG PNG::PNG)
endif()

if(FAIRSEQ2N_USE_CUDA)
target_link_libraries(fairseq2n PRIVATE CUDA::cudart)
endif()


fairseq2n_set_link_options(fairseq2n)

set_target_properties(fairseq2n PROPERTIES
Expand Down
6 changes: 6 additions & 0 deletions fairseq2n/src/fairseq2n/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ constexpr std::optional<std::int32_t> cuda_version_minor = @CUDA_VERSION_MINOR@;

constexpr bool supports_cuda = cuda_version_major.has_value();

#ifdef FAIRSEQ2N_SUPPORT_IMAGE
constexpr bool supports_image = true;
#else
constexpr bool supports_image = false;
#endif

} // namespace fairseq2n
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#pragma once

#include <cstddef>
#include <cstdio>
// Forward declaration
using FILE = struct _IO_FILE;
//using FILE = struct _IO_FILE;
#include <jpeglib.h>

#include "fairseq2n/exception.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace fairseq2n::detail {

png_read::png_read() : png_ptr(nullptr), info_ptr(nullptr) {
png_read::png_read() {
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (png_ptr == nullptr) {
throw internal_error("Failed to create PNG read struct.");
Expand Down
4 changes: 2 additions & 2 deletions fairseq2n/src/fairseq2n/data/image/detail/png_read_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class png_read{
png_read& operator=(const png_read&) = delete;

private:
png_structp png_ptr{nullptr};
png_infop info_ptr{nullptr};
png_structp png_ptr{};
png_infop info_ptr{};
};

} // namespace fairseq2n::detail
Loading

0 comments on commit 3f60fd7

Please sign in to comment.