Install#
ovspatialquery ships as two archives per platform: a Python wheel and a C SDK. Both contain the same native library, and both run queries on the CPU without a GPU, a CUDA driver, or a CUDA Toolkit.
Each release provides these archives:
Platform |
Python Wheel Tag |
SDK |
|---|---|---|
Linux x86-64 (glibc 2.35 or newer) |
|
yes |
Linux AArch64 (glibc 2.35 or newer) |
|
yes |
Windows x64 |
|
yes |
Python Package#
The Python package supports these versions:
Requirement |
Supported Versions |
|---|---|
Python |
3.11, 3.12, 3.13 |
ovstage (optional, to publish from a stage) |
0.3, 0.4 |
ovstage for this guide’s examples |
0.4 |
NVIDIA Warp ( |
1.18 |
Any other array library with |
any release with |
The wheel loads the native library through ctypes, so one wheel serves every supported Python
version on its platform. Install it from PyPI:
python -m pip install ovspatialquery
Every input column is any array with __dlpack__, and every result column can be read the same
way, on the CPU or on a CUDA device. The examples in this guide use
NVIDIA Warp, whose arrays live on either device and whose kernels
can read result columns without a copy:
python -m pip install warp-lang
Note
NumPy is optional. Install it only to copy CPU results into NumPy arrays with to_numpy().
To publish geometry from an ovstage stage, install ovstage from PyPI. The following command installs ovstage 0.4, which this guide’s examples use:
python -m pip install "ovstage==0.4.*"
Note
The examples turn an object ID back into a prim path with
path_to_string(ovstage.PrimPath(object_id)). With ovstage 0.3, which has no PrimPath, pass the
ID itself: path_to_string(object_id).
ovspatialquery checks the ovstage version when you call instance.ovstage(ovstage, stage), before
you create a population, the set of objects that queries read. An unsupported release raises
an error that names the version it found.
Importing ovspatialquery does not load the native library.
Library.open() loads it and looks for it in this order:
The path passed to
Library.open(path).The
OVSPATIALQUERY_LIBRARYenvironment variable.The copy inside the wheel.
To check the installation, open the library and print its version and the file it loaded:
python -c "from ovspatialquery import Library; lib = Library.open(); print(lib.version, lib.path)"
The command prints the native library’s version as three numbers and the path of the library
file. Unless OVSPATIALQUERY_LIBRARY is set, that file is the copy inside the wheel. A library
that cannot be loaded raises LibraryLoadError with the path it tried.
C and C++ SDK#
The SDK archive unpacks to one root:
include/ovspatialquery/ovspatialquery.h scene queries, plans and operations
include/ovspatialquery/ovspatialquery_explicit.h caller-supplied geometry
include/ovspatialquery/ovspatialquery_ovstage.h ovstage populations and views
include/ovspatialquery/ovspatialquery_pairs.h pair snapshots and reporters
include/dlpack/dlpack.h the DLPack tensor header
lib/libovspatialquery.so Linux
lib/ovspatialquery_cuda.ptx CUDA kernels on Linux, next to the library
bin/ovspatialquery.dll, lib/ovspatialquery.lib Windows
bin/ovspatialquery_cuda.ptx CUDA kernels on Windows, next to the DLL
lib/cmake/ovspatialquery/ the CMake package
share/ovspatialquery/ the offline guide and its programs, lessons, agent skill
LICENSE, NOTICE, licenses/
Building a program against the SDK needs these tools:
Tool |
Minimum |
|---|---|
CMake |
3.20 |
C compiler |
C11 |
Point CMAKE_PREFIX_PATH at the SDK root and link the imported target:
cmake_minimum_required(VERSION 3.20)
project(my_app LANGUAGES C)
find_package(ovspatialquery CONFIG REQUIRED)
add_executable(my_app first_query.c)
target_link_libraries(my_app PRIVATE ovspatialquery::ovspatialquery)
Then configure and build the project:
cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/sdk
cmake --build build
With first_query.c from Querying from C, the built program
prints one line. On Linux, run ./build/my_app. On Windows, the program needs the DLL on PATH.
In Command Prompt, run set PATH=C:\path\to\sdk\bin;%PATH% and then build\Debug\my_app.exe.
A single-configuration generator such as Ninja builds build\my_app.exe instead. The program
prints this output:
ray hit 10 at distance 3.500, ordinal 1
ovspatialquery::ovspatialquery carries the include directories for the ovspatialquery and
DLPack headers and the shared library, with its import library on Windows. It also carries the
definition that makes Windows callers import the API from the DLL. Releases with the same major
and minor version are compatible, so a version request such as
find_package(ovspatialquery X.Y CONFIG REQUIRED) accepts any X.Y.z SDK.
Ask for COMPONENTS ovstage to require the ovstage companion header. That header includes
ovstage’s own C headers, and the package does not find ovstage itself. The ovstage Python package
directory, site-packages/ovstage in the environment where you installed ovstage, holds those
headers and ovstage’s CMake package. Add it to CMAKE_PREFIX_PATH, find ovstage, and link its
target next to ovspatialquery’s:
find_package(ovspatialquery CONFIG REQUIRED COMPONENTS ovstage)
find_package(ovstage CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE ovspatialquery::ovspatialquery ovstage::ovstage)
The following command prints that directory:
python -c "import ovstage, os; print(os.path.dirname(ovstage.__file__))"
Pass both roots when you configure, separated by a semicolon:
-DCMAKE_PREFIX_PATH="/path/to/sdk;/path/to/site-packages/ovstage".
On Linux, the build tree’s rpath lets a program find the library while it runs from there. An
installed program needs the library on its own path, through an rpath or LD_LIBRARY_PATH.
Windows has no rpath, so a program finds ovspatialquery.dll next to the executable or on PATH,
in the build tree as well. Add the SDK’s bin directory to PATH, or copy the DLL next to the
program. If you call ovstage functions, also add ovstage’s bin directory to PATH.
Deploy ovspatialquery_cuda.ptx next to the library. The package names it in
ovspatialquery_CUDA_PTX when the SDK has the CUDA backend.
Several Copies in One Process#
A process can load more than one copy of the native library, from different files and from different releases. Each loaded copy keeps its own instances and objects and works independently of the others. A process loads several copies in these cases:
An application links the SDK and also runs Python code that calls
Library.open()withOVSPATIALQUERY_LIBRARYunset, which loads the copy inside the wheel.OVSPATIALQUERY_LIBRARYnames one build, and another part of the program passes a different file toLibrary.open(path).Two packages in one program each bundle their own copy of the library.
A handle or operation ID belongs to the copy that returned it, and passing it to another copy is undefined behavior. Every copy numbers its handles the same way, so the other copy does not detect the mistake. The call can act on an unrelated object of that copy and still return success.
Important
On Linux, a copy from a release earlier than the one this guide describes can send some of its own calls to another copy loaded before it. Load such a copy only in a process that holds no other copy.
Keep each handle with the Library and instance that created it. In Python, use the populations,
views, and targets of an instance only with that instance.
Library.path is the file that a Library loaded, and two Library objects with the same path
share one copy and its handles. On Linux, the following code lists the loaded library files named
libovspatialquery.so, one entry per file. It does not list a copy loaded from a file with another
name, and it shows one entry for copies that dlmopen loads from one file into separate namespaces:
from pathlib import Path
loaded = {}
for line in Path("/proc/self/maps").read_text().splitlines():
fields = line.split(maxsplit=5)
# A file replaced while it is loaded keeps its mapping, marked " (deleted)".
path = fields[-1].removesuffix(" (deleted)")
if len(fields) == 6 and path.endswith("/libovspatialquery.so"):
loaded[fields[3], fields[4]] = path # one entry per device and inode
print(sorted(loaded.values()))
Tip
A program that lends targets to plugins can check that each plugin calls the copy that created
them. It passes the address of ovspatialquery_get_version in the copy that created the target,
and the plugin compares it with the address in the copy it calls. The addresses differ when the
copies differ. Take each address from the copy itself:
In C, use
(uintptr_t)&ovspatialquery_get_versionfor the copy the program links. For a copy it loaded at run time, usedlsymon Linux orGetProcAddresson Windows with that copy’s handle.In Python, use
ctypes.cast(library.exports["ovspatialquery_get_version"], ctypes.c_void_p).valuewith theLibrarythat created the target.
CUDA Devices#
Everything runs on the CPU unless you ask for a GPU. Two objects decide where work runs:
The instance owns everything you create and the memory budgets for all of it. It runs nothing on a GPU unless it is given a byte budget for that CUDA device.
A batch plan answers many queries of one kind (rays, sweeps, or overlaps) per launch. Each plan is created for one device, the CPU or one CUDA device the instance has a budget for. Batches explains plans, and pair reporters choose a device the same way. Single queries, such as
raycast_closest, always run on the CPU.
The following code gives the instance a 256 MiB budget on CUDA device 0:
from ovspatialquery import Device, DeviceBudget, InstanceConfig, Library
config = InstanceConfig(device_budgets=(DeviceBudget(Device.cuda(0), 256 << 20),))
with Library.open() as library, library.instance(config) as instance:
... # create plans with device=Device.cuda(0)
The library tries to load the CUDA driver the first time it places work on a CUDA device or
checks whether it can use one. A capability question about a CUDA device, which is
ovspatialquery_query_capability() in C and
supports in Python, makes that check for every
capability the library knows. It does so even when the instance has no budget for that device
and the answer is no. The library does not need the CUDA runtime or the CUDA runtime compiler
(NVRTC).
Important
CUDA work never falls back to the CPU. If CUDA is not available, creating a CUDA plan returns
NOT_SUPPORTED, which Python raises as an error, and ovspatialquery_get_last_error()
says why.
CUDA work has these minimum requirements:
Requirement |
Minimum |
|---|---|
GPU compute capability |
7.5 (Turing) |
CUDA driver version |
12.8 (R570) |
NVIDIA driver on Linux |
570.26 |
NVIDIA driver on Windows |
570.65 |
The driver compiles the bundled ovspatialquery_cuda.ptx when the library first uses the device.
Note
The Warp 1.18 wheels on PyPI are built with CUDA 13, so Warp arrays and kernels on a GPU need an NVIDIA R580-series or newer driver. On an R570 driver, ovspatialquery’s CUDA plans still run, and Warp works on the CPU. Refer to the Warp compatibility guide for Warp builds that support older drivers.
Source Builds#
The README.md file in the source distribution describes how to build the library from source.
A source build reports the first version that applies from this table:
Version Source |
Reported Version |
|---|---|
The |
The version you set, in the form |
The |
The version of that release |
A Git checkout with no local changes whose |
The version of that tag, or the final release when both tags apply |
None of these |
The development version, such as |
A development build prints a line that names its version and the variable that overrides it. The
version getter returns the numeric X.Y.Z part in every case. The editable package in the build’s
own virtual environment keeps the development version in its package metadata. The SDK and the
wheel carry the reported version.