Skip to content
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
37 changes: 34 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,17 @@ execute_process(
"${PYTHON_EXECUTABLE}" -c "import nanobind; print(nanobind.cmake_dir())"
OUTPUT_VARIABLE NANOBIND_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
list(APPEND CMAKE_PREFIX_PATH "${NANOBIND_DIR}")
list(APPEND CMAKE_PREFIX_PATH "${NANOBIND_DIR}")

execute_process(
COMMAND
"${PYTHON_EXECUTABLE}" -c "import nanobind; print(nanobind.include_dir())"
OUTPUT_VARIABLE NANOBIND_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)

# }}}

link_directories(${CL_LIB_DIR})
include_directories(${CL_INC_DIR} ${Python_NumPy_INCLUDE_DIRS})

find_package(nanobind CONFIG REQUIRED)

set(OpenCL_ROOT ${CL_LIB_DIR})
Expand All @@ -167,6 +171,7 @@ find_package(OpenCL REQUIRED)
nanobind_add_module(
_cl
NB_STATIC # Build static libnanobind (the extension module itself remains a shared library)
NB_SUPPRESS_WARNINGS
LTO
NOMINSIZE
src/wrap_constants.cpp
Expand All @@ -176,15 +181,41 @@ nanobind_add_module(
src/wrap_mempool.cpp
src/bitlog.cpp
)
target_compile_features(_cl PRIVATE cxx_std_17)

target_link_libraries(_cl PRIVATE ${OpenCL_LIBRARY})
target_include_directories(_cl SYSTEM PRIVATE
${CL_INC_DIR}
${NANOBIND_INCLUDE_DIR}
${Python_NumPy_INCLUDE_DIRS})
Comment on lines +187 to +190

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mainly needed so that gcc/clang don't complain about warnings in these headers. I think NB_SUPRESS_WARNINGS already does most of this, but added it with CL and NumPy just in case.


target_compile_definitions(_cl
PRIVATE
PYGPU_PACKAGE=pyopencl
PYGPU_PYOPENCL
)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(_cl PRIVATE
-Wall
-Wextra
# NOTE: VLAs are used by PYOPENCL_STACK_CONTAINER for dubious reasons
-Wpedantic -Wno-vla
Comment on lines +202 to +203

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That VLA in there is pretty old. Still useful? Even the Linux kernel removed VLAs 😁

-Wshadow
-Wold-style-cast
-Wcast-align
-Wconversion -Wsign-conversion
-Wnon-virtual-dtor
-Woverloaded-virtual
-Wformat=2
-Wimplicit-fallthrough
-Wdouble-promotion
-Wnull-dereference
# NOTE: mostly calls to deprecated CL functions that we support
-Wno-deprecated-declarations
)
endif()
Comment on lines +198 to +217

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loads of random warnings here. The -Wconversion ones are a bit noisy, but overall they should be ok?


if (PYOPENCL_PRETEND_CL_VERSION)
target_compile_definitions(
_cl PRIVATE PYOPENCL_PRETEND_CL_VERSION=${PYOPENCL_PRETEND_CL_VERSION})
Expand Down
2 changes: 1 addition & 1 deletion src/bitlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "bitlog.hpp"


const char pyopencl::log_table_8[] =
const unsigned char pyopencl::log_table_8[] =
{
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
Expand Down
10 changes: 5 additions & 5 deletions src/bitlog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace pyopencl
{
/* from http://graphics.stanford.edu/~seander/bithacks.html */

extern const char log_table_8[];
extern const unsigned char log_table_8[];

inline unsigned bitlog2_16(uint16_t v)
{
Expand All @@ -49,19 +49,19 @@ namespace pyopencl

inline unsigned bitlog2_32(uint32_t v)
{
if (uint16_t t = v >> 16)
if (uint16_t t = static_cast<uint16_t>(v >> 16))
return 16+bitlog2_16(t);
else
return bitlog2_16(v);
return bitlog2_16(static_cast<uint16_t>(v));
}

#if defined(UINT64_MAX)
inline unsigned bitlog2(uint64_t v)
{
if (uint32_t t = v >> 32)
if (uint32_t t = static_cast<uint32_t>(v >> 32))
return 32+bitlog2_32(t);
else
return bitlog2_32(v);
return bitlog2_32(static_cast<uint32_t>(v));
}
#else
inline unsigned bitlog2(unsigned long v)
Expand Down
10 changes: 5 additions & 5 deletions src/mempool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,18 @@ namespace PYGPU_PACKAGE
private:
unsigned mantissa_mask() const
{
return (1 << m_leading_bits_in_bin_id) - 1;
return (1u << m_leading_bits_in_bin_id) - 1;
}

public:
bin_nr_t bin_number(size_type size)
{
signed l = bitlog2(size);
signed l = static_cast<signed>(bitlog2(size));
size_type shifted = signed_right_shift(size, l-signed(m_leading_bits_in_bin_id));
if (size && (shifted & (1 << m_leading_bits_in_bin_id)) == 0)
throw std::runtime_error("memory_pool::bin_number: bitlog2 fault");
size_type chopped = shifted & mantissa_mask();
return l << m_leading_bits_in_bin_id | chopped;
return static_cast<bin_nr_t>(static_cast<size_type>(l) << m_leading_bits_in_bin_id | chopped);
}

void set_trace(bool flag)
Expand All @@ -185,13 +185,13 @@ namespace PYGPU_PACKAGE
bin_nr_t exponent = bin >> m_leading_bits_in_bin_id;
bin_nr_t mantissa = bin & mantissa_mask();

size_type ones = signed_left_shift((size_type) 1,
size_type ones = signed_left_shift(static_cast<size_type>(1),
signed(exponent)-signed(m_leading_bits_in_bin_id)
);
if (ones) ones -= 1;

size_type head = signed_left_shift(
(size_type) ((1<<m_leading_bits_in_bin_id) | mantissa),
static_cast<size_type>((1<<m_leading_bits_in_bin_id) | mantissa),
signed(exponent)-signed(m_leading_bits_in_bin_id));
if (ones & head)
throw std::runtime_error("memory_pool::alloc_size: bit-counting fault");
Expand Down
Loading
Loading