Skip to content

[C API] Add OpenMP support validation in ThreadPoolBuilder - #412

Merged
rfsaliev merged 4 commits into
mainfrom
rfsaliev/c-api-fix-omp
Oct 16, 2026
Merged

rfsaliev merged 4 commits into
mainfrom
rfsaliev/c-api-fix-omp

Conversation

@rfsaliev

@rfsaliev rfsaliev commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

This pull request improves the handling of OpenMP thread pool support in the C bindings, making OpenMP an optional feature that can be toggled at build time. It ensures that the API and documentation clearly indicate when OpenMP is available, returns appropriate errors if OpenMP is requested but not built in, and updates tests to handle both configurations. The main changes are grouped below:

Build System and Feature Flagging:

  • Added a new SVS_ENABLE_OMP CMake option (enabled by default) to control whether OpenMP thread pool support is built into the library. The build system now only enables OpenMP-related code and definitions if this option is set and OpenMP is found. Default symbol visibility is also set to hidden for shared libraries. [1] [2] [3]

API Behavior and Error Handling:

  • Updated the thread pool API (svs_index_builder_set_threadpool) and its documentation to clarify that selecting the OpenMP thread pool kind will fail with SVS_ERROR_NOT_IMPLEMENTED if the library was not built with OpenMP support. The implementation now checks for OpenMP support at runtime and throws an appropriate error if unavailable. [1] [2] [3] [4]

Documentation Updates:

  • Improved documentation in C_API_Design.md and header comments to accurately reflect the conditional availability of OpenMP thread pools and the associated error handling. [1] [2]

Testing Improvements:

  • Updated C API tests to check for OpenMP support at runtime using a new check_openmp_support helper, allowing tests to pass whether or not OpenMP is enabled in the build. Test code now conditionally executes OpenMP-specific assertions and logic. [1] [2] [3] [4]

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tests accept either capability state and therefore cannot detect broken OpenMP build configuration.

2 open findings
What changed in this PR

Adds optional OpenMP support handling to the C API.

Changes:

  • Conditionally enables OpenMP and returns SVS_ERROR_NOT_IMPLEMENTED when unavailable.
  • Updates public documentation for OpenMP thread pools.
  • Adapts thread-pool tests for OpenMP-disabled builds.
File Description
bindings/​c/​CMakeLists.txt Makes OpenMP optional.
bindings/​c/​src/​threadpool.hpp Validates OpenMP availability.
bindings/​c/​include/​svs/​c/​svs_c.h Documents availability and errors.
bindings/​c/​docs/​C_API_Design.md Updates thread-pool guidance.
bindings/​c/​tests/​c_api_index.cpp Adjusts OMP index tests.
bindings/​c/​tests/​c_api_index_builder.cpp Adjusts OMP builder tests.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread bindings/c/tests/c_api_index.cpp Outdated
Comment thread bindings/c/tests/c_api_index_builder.cpp Outdated
@rfsaliev
rfsaliev force-pushed the rfsaliev/c-api-fix-omp branch from 546debd to 6bc4d2a Compare October 12, 2026 10:27
@rfsaliev
rfsaliev requested a balanced review from Copilot October 12, 2026 10:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

6 open findings

🧠 Review effort: Lite

Comment thread bindings/c/src/threadpool.hpp Outdated
Comment thread bindings/c/src/threadpool.hpp
Comment thread bindings/c/tests/CMakeLists.txt Outdated
Comment thread bindings/c/tests/c_api_test_utils.h

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

7 open findings
6 resolved since last review

🧠 Review effort: Lite

Comment thread bindings/c/src/threadpool.hpp
Comment thread bindings/c/src/threadpool.hpp
Comment thread bindings/c/CMakeLists.txt
Comment thread bindings/c/include/svs/c/svs_c.h Outdated
Comment thread bindings/c/tests/CMakeLists.txt Outdated
Comment thread bindings/c/src/threadpool.hpp
Comment thread bindings/c/src/threadpool.hpp

@ethanglaser ethanglaser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall LGTM

Comment thread bindings/c/CMakeLists.txt Outdated
Comment on lines +73 to +80
find_package(OpenMP)
if (OpenMP_CXX_FOUND)
# PRIVATE: OpenMP is an implementation detail linked into the shared library.
# Exporting it would force consumers of the C ABI to resolve a C++ OpenMP
# target they never asked for.
target_link_libraries(${TARGET_NAME} PRIVATE OpenMP::OpenMP_CXX)
target_compile_definitions(${TARGET_NAME} PRIVATE SVS_ENABLE_OMP=1)
endif() # OpenMP_CXX_FOUND

@ethanglaser ethanglaser Oct 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Only concern here is that OpenMP could be silently not found. What if instead the findpackage was moved inside a conditional related to the flag, something like:

Suggested change
find_package(OpenMP)
if (OpenMP_CXX_FOUND)
# PRIVATE: OpenMP is an implementation detail linked into the shared library.
# Exporting it would force consumers of the C ABI to resolve a C++ OpenMP
# target they never asked for.
target_link_libraries(${TARGET_NAME} PRIVATE OpenMP::OpenMP_CXX)
target_compile_definitions(${TARGET_NAME} PRIVATE SVS_ENABLE_OMP=1)
endif() # OpenMP_CXX_FOUND
if (SVS_C_API_ENABLE_OPENMP)
find_package(OpenMP REQUIRED)
# PRIVATE: OpenMP is an implementation detail linked into the shared library.
# Exporting it would force consumers of the C ABI to resolve a C++ OpenMP
# target they never asked for.
target_link_libraries(${TARGET_NAME} PRIVATE OpenMP::OpenMP_CXX)
target_compile_definitions(${TARGET_NAME} PRIVATE SVS_ENABLE_OMP=1)
endif() # OpenMP_CXX_FOUND

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed by adding the option SVS_ENABLE_OMP which is ON by default

@mergify

mergify Bot commented Oct 13, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@rfsaliev
rfsaliev force-pushed the rfsaliev/c-api-fix-omp branch from 935a534 to 1674200 Compare October 15, 2026 17:19
@rfsaliev
rfsaliev requested a review from mihaic as a code owner October 15, 2026 17:19
@izaakk

izaakk commented Oct 15, 2026

Copy link
Copy Markdown

LGTM, verified from the consumer side. valkey-search compiles the C API sources itself without OpenMP and has been force-including a stub for the unguarded OMPThreadPool reference (eshenayo/valkey-search#19). With these commits on our pin 8285340 and the stub deleted, the build is clean in Release and Debug, the link gate passes with no libgomp, and all tests pass. This is exactly the guard we needed.

Comment thread bindings/c/tests/CMakeLists.txt Outdated
@rfsaliev
rfsaliev merged commit fd23725 into main Oct 16, 2026
19 of 21 checks passed
@rfsaliev
rfsaliev deleted the rfsaliev/c-api-fix-omp branch October 16, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C API] Guard SVS_THREADPOOL_KIND_OMP case in threadpool.hpp behind #if SVS_OMP

4 participants