Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fixes for Windows / Visual Studio #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,18 @@ if (NDZIP_BUILD_BENCHMARK AND NDZIP_WITH_3RDPARTY_BENCHMARKS)
endif ()


set(CMAKE_CXX_STANDARD 17)
if (NOT MSVC)
set(CMAKE_CXX_STANDARD 17)
else ()
set(CMAKE_CXX_STANDARD 20) # to_string under MSVC needs C++20
endif ()

set(CMAKE_CUDA_STANDARD 17)

set(NDZIP_COMPILE_FLAGS -Wall -Wextra -Wno-attributes -Wimplicit-fallthrough)
set(NDZIP_CXX_FLAGS ${NDZIP_COMPILE_FLAGS} -Werror=return-type -Werror=init-self -Werror=undef)
if (NOT MSVC)
set(NDZIP_COMPILE_FLAGS -Wall -Wextra -Wno-attributes -Wimplicit-fallthrough)
set(NDZIP_CXX_FLAGS ${NDZIP_COMPILE_FLAGS} -Werror=return-type -Werror=init-self -Werror=undef)
endif()

if (NDZIP_USE_HIPSYCL)
# Aggressive inlining avoids GPU call stack allocation == global memory access bottleneck
Expand Down Expand Up @@ -107,14 +114,21 @@ set(NDZIP_PROFILE_CONFIGURATIONS
VARIABLE DIMENSIONS VALUES 1 2 3
)

add_library(ndzip SHARED
set(NDZIP_LIB_SOURCES
include/ndzip/ndzip.hh
include/ndzip/offload.hh
src/ndzip/common.hh
src/ndzip/common.cc
src/ndzip/cpu_codec.inl
src/ndzip/cpu_factory.cc
)

if (MSVC)
# on windows, build as static library since symbol exports are not setup there
add_library(ndzip STATIC ${NDZIP_LIB_SOURCES})
else ()
add_library(ndzip SHARED ${NDZIP_LIB_SOURCES})
endif ()
target_split_configured_sources(ndzip PRIVATE
GENERATE cpu_encoder.cc FROM src/ndzip/cpu_codec.inl
${NDZIP_PROFILE_CONFIGURATIONS}
Expand Down
6 changes: 6 additions & 0 deletions src/ndzip/common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ NDZIP_UNIVERSAL inline unsigned popcount(unsigned int x) {
#ifdef __CUDA_ARCH__
// NVCC regards __builtin_popcount as a __host__ function
return __popc(static_cast<int>(x));
#elif defined(_MSC_VER)
return __popcnt(x);
#else
return __builtin_popcount(x);
#endif
Expand All @@ -604,6 +606,8 @@ NDZIP_UNIVERSAL inline unsigned popcount(unsigned long x) {
static_assert(sizeof(unsigned long) == sizeof(unsigned long long));
return __popcll(static_cast<long long>(x));
}
#elif defined(_MSC_VER)
return __popcnt64(x);
#else
return __builtin_popcountl(x);
#endif
Expand All @@ -613,6 +617,8 @@ NDZIP_UNIVERSAL inline unsigned popcount(unsigned long long x) {
#ifdef __CUDA_ARCH__
// NVCC regards __builtin_popcountll as a __host__ function
return __popcll(static_cast<long long>(x));
#elif defined(_MSC_VER)
return __popcnt64(x);
#else
return __builtin_popcountll(x);
#endif
Expand Down
25 changes: 21 additions & 4 deletions src/ndzip/cpu_codec.inl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <immintrin.h>
#endif

#ifdef NDZIP_OPENMP_SUPPORT
#if NDZIP_OPENMP_SUPPORT
#include <atomic>
#include <omp.h>
#include <queue>
Expand Down Expand Up @@ -42,20 +42,20 @@ class simd_aligned_buffer {

explicit simd_aligned_buffer(size_t size) {
assert(size % simd_width_bytes == 0);
_memory = std::aligned_alloc(simd_width_bytes, size * sizeof(T));
_memory = aligned_alloc(size);
if (!_memory) { throw std::bad_alloc(); }
}

simd_aligned_buffer(simd_aligned_buffer &&other) noexcept { *this = std::move(other); }

simd_aligned_buffer &operator=(simd_aligned_buffer &&other) noexcept {
std::free(_memory);
aligned_free(_memory);
_memory = other._memory;
other._memory = nullptr;
return *this;
}

~simd_aligned_buffer() { std::free(_memory); }
~simd_aligned_buffer() { aligned_free(_memory); }

explicit operator bool() const { return _memory != nullptr; }

Expand All @@ -67,6 +67,23 @@ class simd_aligned_buffer {

const T &operator[](size_t i) const { return data()[i]; };

private:
static void *aligned_alloc(size_t size)
{
#ifdef _MSC_VER
return _aligned_malloc(size * sizeof(T), simd_width_bytes);
#else
return std::aligned_alloc(simd_width_bytes, size * sizeof(T));
#endif
}
static void aligned_free(void *mem)
{
#ifdef _MSC_VER
return _aligned_free(mem);
#else
return std::free(mem);
#endif
}
private:
void *_memory = nullptr;
};
Expand Down