poselib-gpu 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. poselib_gpu-0.1.0/.gitignore +8 -0
  2. poselib_gpu-0.1.0/.lycheeignore +3 -0
  3. poselib_gpu-0.1.0/CMakeLists.txt +357 -0
  4. poselib_gpu-0.1.0/LICENSE +202 -0
  5. poselib_gpu-0.1.0/LICENSE.PoseLib +29 -0
  6. poselib_gpu-0.1.0/PKG-INFO +91 -0
  7. poselib_gpu-0.1.0/PLAN.md +530 -0
  8. poselib_gpu-0.1.0/README.md +203 -0
  9. poselib_gpu-0.1.0/bindings/python/CMakeLists.txt +59 -0
  10. poselib_gpu-0.1.0/bindings/python/README.md +66 -0
  11. poselib_gpu-0.1.0/bindings/python/build_info.py.in +6 -0
  12. poselib_gpu-0.1.0/bindings/python/poselib_gpu/__init__.py +291 -0
  13. poselib_gpu-0.1.0/bindings/python/poselib_gpu/py.typed +0 -0
  14. poselib_gpu-0.1.0/bindings/python/requirements.txt +3 -0
  15. poselib_gpu-0.1.0/bindings/python/src/module.cpp +215 -0
  16. poselib_gpu-0.1.0/bindings/python/tests/test_bindings.py +177 -0
  17. poselib_gpu-0.1.0/cli/bench.cpp +333 -0
  18. poselib_gpu-0.1.0/cli/main.cpp +293 -0
  19. poselib_gpu-0.1.0/cli/problem_file.h +212 -0
  20. poselib_gpu-0.1.0/cli/synth.h +227 -0
  21. poselib_gpu-0.1.0/cmake/embed_text.cmake +14 -0
  22. poselib_gpu-0.1.0/cmake/jpoConfig.cmake.in +56 -0
  23. poselib_gpu-0.1.0/include/jpo/jpo.h +155 -0
  24. poselib_gpu-0.1.0/packaging/fetch_cuda.py +101 -0
  25. poselib_gpu-0.1.0/packaging/variant.py +62 -0
  26. poselib_gpu-0.1.0/packaging/version.py +98 -0
  27. poselib_gpu-0.1.0/pyproject.toml +82 -0
  28. poselib_gpu-0.1.0/src/backend/backend.h +66 -0
  29. poselib_gpu-0.1.0/src/backend/cpu/cpu_backend.cpp +156 -0
  30. poselib_gpu-0.1.0/src/backend/cpu/kernels_cpu.h +61 -0
  31. poselib_gpu-0.1.0/src/backend/cuda/cuda_backend.cu +232 -0
  32. poselib_gpu-0.1.0/src/backend/metal/entry.metal +115 -0
  33. poselib_gpu-0.1.0/src/backend/metal/metal_backend.mm +190 -0
  34. poselib_gpu-0.1.0/src/backend/metal/prelude.metal +24 -0
  35. poselib_gpu-0.1.0/src/backend/webgpu/kernels.wgsl +1609 -0
  36. poselib_gpu-0.1.0/src/backend/webgpu/webgpu_backend.cpp +505 -0
  37. poselib_gpu-0.1.0/src/core/api.cpp +212 -0
  38. poselib_gpu-0.1.0/src/core/api_internal.h +20 -0
  39. poselib_gpu-0.1.0/src/core/auto_rule.cpp +83 -0
  40. poselib_gpu-0.1.0/src/core/estimator.cpp +514 -0
  41. poselib_gpu-0.1.0/src/core/estimator.h +45 -0
  42. poselib_gpu-0.1.0/src/core/geometry.cpp +752 -0
  43. poselib_gpu-0.1.0/src/core/geometry.h +64 -0
  44. poselib_gpu-0.1.0/src/core/pool.h +104 -0
  45. poselib_gpu-0.1.0/src/kernels/kernels.inc +1135 -0
  46. poselib_gpu-0.1.0/tests/backend_test.cpp +346 -0
  47. poselib_gpu-0.1.0/tests/core_test.cpp +359 -0
  48. poselib_gpu-0.1.0/tests/incremental/CMakeLists.txt +38 -0
  49. poselib_gpu-0.1.0/tests/incremental/incremental_test.cpp +821 -0
  50. poselib_gpu-0.1.0/tests/incremental/scenes.h +300 -0
  51. poselib_gpu-0.1.0/tests/package/CMakeLists.txt +11 -0
  52. poselib_gpu-0.1.0/tests/package/main.c +95 -0
  53. poselib_gpu-0.1.0/tests/package/run.cmake +33 -0
  54. poselib_gpu-0.1.0/tests/parity_test.cpp +104 -0
  55. poselib_gpu-0.1.0/tests/precision_test.cpp +151 -0
  56. poselib_gpu-0.1.0/tests/webgpu_shared_test.cpp +233 -0
@@ -0,0 +1,8 @@
1
+ /third_party/
2
+ /build/
3
+ __pycache__/
4
+ *.pyc
5
+ .venv/
6
+ venv/
7
+ .DS_Store
8
+ /docs/_build/
@@ -0,0 +1,3 @@
1
+ # Pages that exist only in the built documentation site (docs/conf.py puts them there), linked from docs/*.md.
2
+ demo/index\.html$
3
+ benchmark/index\.html$
@@ -0,0 +1,357 @@
1
+ cmake_minimum_required(VERSION 3.16...3.31)
2
+ project(poselib_gpu VERSION 0.1.0 LANGUAGES CXX)
3
+
4
+ option(JPO_BUILD_CLI "Build the jpo command line tool" ON)
5
+ option(JPO_BUILD_TESTS "Build tests" ON)
6
+ option(JPO_BUILD_WASM "Emscripten: build the WebAssembly module, JS wrapper and test page (web/)" ON)
7
+ option(JPO_BUILD_PYTHON "Build the Python module poselib_gpu (needs nanobind; bindings/python/README.md)" OFF)
8
+ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
9
+ set(jpo_top_level ON)
10
+ else()
11
+ set(jpo_top_level OFF)
12
+ endif()
13
+ option(JPO_INSTALL "Install rules: the library, its header, the command line tool and the CMake package" ${jpo_top_level})
14
+ set(JPO_CUDA "AUTO" CACHE STRING "CUDA backend: AUTO (build it when a CUDA compiler is found), ON or OFF")
15
+ set_property(CACHE JPO_CUDA PROPERTY STRINGS AUTO ON OFF)
16
+ set(JPO_METAL "AUTO" CACHE STRING "Metal backend (Apple platforms): AUTO, ON or OFF")
17
+ set_property(CACHE JPO_METAL PROPERTY STRINGS AUTO ON OFF)
18
+ set(JPO_WEBGPU "AUTO" CACHE STRING "WebGPU backend: AUTO (build it when Dawn, or under Emscripten emdawnwebgpu, is found), ON or OFF")
19
+ set_property(CACHE JPO_WEBGPU PROPERTY STRINGS AUTO ON OFF)
20
+ set(JPO_REFERENCE "AUTO" CACHE STRING "PoseLib reference tool and parity tests: AUTO (when third_party/poselib and eigen exist), ON or OFF")
21
+ set_property(CACHE JPO_REFERENCE PROPERTY STRINGS AUTO ON OFF)
22
+
23
+ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
24
+ set(CMAKE_BUILD_TYPE Release)
25
+ endif()
26
+ set(CMAKE_CXX_STANDARD 17)
27
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
28
+ set(CMAKE_CXX_EXTENSIONS OFF)
29
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
30
+ if(EMSCRIPTEN)
31
+ # Native wasm exceptions, as the sibling libraries: one app links them all into one module.
32
+ add_compile_options(-fwasm-exceptions)
33
+ add_link_options(-fwasm-exceptions)
34
+ endif()
35
+
36
+ # CUDA backend: needs only the CUDA toolkit (nvcc and its runtime library).
37
+ if(NOT JPO_CUDA STREQUAL "OFF" AND NOT EMSCRIPTEN)
38
+ if(NOT CMAKE_CUDA_COMPILER AND NOT DEFINED ENV{CUDACXX})
39
+ find_program(JPO_NVCC nvcc HINTS ENV CUDA_PATH PATHS /opt/cuda /usr/local/cuda PATH_SUFFIXES bin)
40
+ if(JPO_NVCC)
41
+ set(CMAKE_CUDA_COMPILER "${JPO_NVCC}")
42
+ endif()
43
+ endif()
44
+ include(CheckLanguage)
45
+ check_language(CUDA)
46
+ if(CMAKE_CUDA_COMPILER)
47
+ enable_language(CUDA)
48
+ set(JPO_HAVE_CUDA ON)
49
+ elseif(JPO_CUDA STREQUAL "ON")
50
+ message(FATAL_ERROR "JPO_CUDA=ON but no CUDA compiler was found (set CUDACXX or CMAKE_CUDA_COMPILER)")
51
+ endif()
52
+ endif()
53
+
54
+ # Metal backend: Metal.framework and Foundation. Shaders are compiled at run time.
55
+ if(NOT JPO_METAL STREQUAL "OFF")
56
+ if(APPLE)
57
+ find_library(JPO_METAL_FRAMEWORK Metal)
58
+ find_library(JPO_FOUNDATION_FRAMEWORK Foundation)
59
+ endif()
60
+ if(JPO_METAL_FRAMEWORK AND JPO_FOUNDATION_FRAMEWORK)
61
+ enable_language(OBJCXX)
62
+ set(JPO_HAVE_METAL ON)
63
+ elseif(JPO_METAL STREQUAL "ON")
64
+ message(FATAL_ERROR "JPO_METAL=ON but Metal.framework was not found (Apple platforms only)")
65
+ endif()
66
+ endif()
67
+
68
+ # WebGPU backend: natively against Dawn's prebuilt release, under Emscripten against emdawnwebgpu from
69
+ # the same release (tools/fetch_webgpu.sh). Kernels are WGSL, compiled at run time.
70
+ if(NOT JPO_WEBGPU STREQUAL "OFF")
71
+ if(EMSCRIPTEN)
72
+ set(JPO_EMDAWNWEBGPU_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/webgpu/emdawnwebgpu/emdawnwebgpu_pkg"
73
+ CACHE PATH "The unpacked emdawnwebgpu_pkg of a Dawn release")
74
+ if(EXISTS "${JPO_EMDAWNWEBGPU_DIR}/emdawnwebgpu.port.py")
75
+ set(JPO_HAVE_WEBGPU ON)
76
+ endif()
77
+ else()
78
+ file(GLOB jpo_dawn_default "${CMAKE_CURRENT_SOURCE_DIR}/third_party/webgpu/dawn/Dawn-*")
79
+ set(JPO_DAWN_DIR "${jpo_dawn_default}" CACHE PATH "The unpacked Dawn release (with lib/cmake/Dawn)")
80
+ find_package(Dawn CONFIG QUIET PATHS "${JPO_DAWN_DIR}/lib/cmake/Dawn" "${JPO_DAWN_DIR}/lib64/cmake/Dawn"
81
+ NO_DEFAULT_PATH)
82
+ if(Dawn_FOUND)
83
+ set(JPO_HAVE_WEBGPU ON)
84
+ endif()
85
+ endif()
86
+ if(NOT JPO_HAVE_WEBGPU AND JPO_WEBGPU STREQUAL "ON")
87
+ message(FATAL_ERROR "JPO_WEBGPU=ON but neither Dawn (JPO_DAWN_DIR) nor, under Emscripten, emdawnwebgpu "
88
+ "(JPO_EMDAWNWEBGPU_DIR) was found")
89
+ endif()
90
+ endif()
91
+
92
+ include(GNUInstallDirs)
93
+ add_library(jpo
94
+ src/core/api.cpp
95
+ src/core/auto_rule.cpp
96
+ src/core/estimator.cpp
97
+ src/core/geometry.cpp
98
+ src/backend/cpu/cpu_backend.cpp)
99
+ add_library(jpo::jpo ALIAS jpo)
100
+ target_include_directories(jpo PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
101
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
102
+ PRIVATE src)
103
+ # The header has no export macros: a Windows DLL exports every symbol (the API is all jpo_ functions).
104
+ set_target_properties(jpo PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}
105
+ WINDOWS_EXPORT_ALL_SYMBOLS ON)
106
+ if(NOT EMSCRIPTEN)
107
+ find_package(Threads REQUIRED)
108
+ target_link_libraries(jpo PRIVATE Threads::Threads)
109
+ endif()
110
+ if(EMSCRIPTEN)
111
+ # Built with native wasm exceptions (above): the module that links jpo must use them too.
112
+ target_link_options(jpo INTERFACE -fwasm-exceptions)
113
+ endif()
114
+ if(NOT MSVC)
115
+ # Fused multiply-add is left to the compiler (measured 15-25 % faster on Apple silicon). Backends
116
+ # therefore agree on the best hypothesis except at near ties, not bit for bit; tests compare that way.
117
+ target_compile_options(jpo PRIVATE $<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Wall;-Wextra>)
118
+ endif()
119
+
120
+ # One kernel source for CPU, CUDA and Metal: src/kernels/kernels.inc.
121
+ set(jpo_kernels "${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/kernels.inc")
122
+ set_property(SOURCE src/backend/cpu/cpu_backend.cpp APPEND PROPERTY OBJECT_DEPENDS "${jpo_kernels}")
123
+
124
+ if(JPO_HAVE_CUDA)
125
+ target_sources(jpo PRIVATE src/backend/cuda/cuda_backend.cu)
126
+ set_property(SOURCE src/backend/cuda/cuda_backend.cu APPEND PROPERTY OBJECT_DEPENDS "${jpo_kernels}")
127
+ target_compile_definitions(jpo PRIVATE JPO_HAVE_CUDA)
128
+ # The runtime is linked by name rather than left to CMake's CUDA language support, so that a project
129
+ # that finds the installed package links it without enabling CUDA itself.
130
+ find_package(CUDAToolkit REQUIRED)
131
+ set_target_properties(jpo PROPERTIES CUDA_STANDARD 17 CUDA_STANDARD_REQUIRED ON CUDA_RUNTIME_LIBRARY None)
132
+ target_link_libraries(jpo PRIVATE CUDA::cudart_static)
133
+ endif()
134
+
135
+ if(JPO_HAVE_METAL)
136
+ # The Metal source is the prelude followed by the shared kernels and the entry points.
137
+ set(metal_cpp "${CMAKE_CURRENT_BINARY_DIR}/metal_kernels.cpp")
138
+ set(metal_parts "${CMAKE_CURRENT_SOURCE_DIR}/src/backend/metal/prelude.metal" "${jpo_kernels}"
139
+ "${CMAKE_CURRENT_SOURCE_DIR}/src/backend/metal/entry.metal")
140
+ string(REPLACE ";" "|" metal_parts_arg "${metal_parts}")
141
+ add_custom_command(
142
+ OUTPUT "${metal_cpp}"
143
+ COMMAND ${CMAKE_COMMAND} "-DIN=${metal_parts_arg}" "-DOUT=${metal_cpp}" -DNAME=kJpoMetalSource
144
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/embed_text.cmake"
145
+ DEPENDS ${metal_parts} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/embed_text.cmake"
146
+ VERBATIM)
147
+ target_sources(jpo PRIVATE src/backend/metal/metal_backend.mm "${metal_cpp}")
148
+ target_compile_definitions(jpo PRIVATE JPO_HAVE_METAL)
149
+ target_compile_options(jpo PRIVATE $<$<COMPILE_LANGUAGE:OBJCXX>:-fobjc-arc>)
150
+ # By name, not by the SDK path find_library returned: the installed package must not carry that path.
151
+ target_link_libraries(jpo PRIVATE "-framework Metal" "-framework Foundation")
152
+ endif()
153
+
154
+ if(JPO_HAVE_WEBGPU)
155
+ set(wgsl_src "${CMAKE_CURRENT_SOURCE_DIR}/src/backend/webgpu/kernels.wgsl")
156
+ set(wgsl_cpp "${CMAKE_CURRENT_BINARY_DIR}/webgpu_kernels.cpp")
157
+ add_custom_command(
158
+ OUTPUT "${wgsl_cpp}"
159
+ COMMAND ${CMAKE_COMMAND} "-DIN=${wgsl_src}" "-DOUT=${wgsl_cpp}" -DNAME=kJpoWgslSource
160
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/embed_text.cmake"
161
+ DEPENDS "${wgsl_src}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/embed_text.cmake"
162
+ VERBATIM)
163
+ target_sources(jpo PRIVATE src/backend/webgpu/webgpu_backend.cpp "${wgsl_cpp}")
164
+ target_compile_definitions(jpo PRIVATE JPO_HAVE_WEBGPU)
165
+ if(EMSCRIPTEN)
166
+ # PUBLIC: whatever links jpo into a module needs the port's JavaScript library too.
167
+ # The installed package adds the same options in jpoConfig.cmake, from a directory the consumer can
168
+ # change (JPO_EMDAWNWEBGPU_DIR), instead of this machine's path.
169
+ target_compile_options(jpo PUBLIC "$<BUILD_INTERFACE:--use-port=${JPO_EMDAWNWEBGPU_DIR}/emdawnwebgpu.port.py>")
170
+ target_link_options(jpo PUBLIC "$<BUILD_INTERFACE:--use-port=${JPO_EMDAWNWEBGPU_DIR}/emdawnwebgpu.port.py>")
171
+ else()
172
+ target_link_libraries(jpo PUBLIC dawn::webgpu_dawn)
173
+ endif()
174
+ endif()
175
+
176
+ set(jpo_backends cpu)
177
+ foreach(b CUDA METAL WEBGPU)
178
+ if(JPO_HAVE_${b})
179
+ string(TOLOWER ${b} name)
180
+ list(APPEND jpo_backends ${name})
181
+ endif()
182
+ endforeach()
183
+ string(REPLACE ";" ", " jpo_backends_text "${jpo_backends}")
184
+ message(STATUS "jpo backends: ${jpo_backends_text}")
185
+
186
+ # The CMake package: find_package(jpo [COMPONENTS cuda metal webgpu]) and target jpo::jpo, from an
187
+ # install prefix or from this build tree. A component is a backend this build has.
188
+ if(JPO_INSTALL)
189
+ include(CMakePackageConfigHelpers)
190
+ set(jpo_cmake_dir "${CMAKE_INSTALL_LIBDIR}/cmake/jpo")
191
+ install(TARGETS jpo EXPORT jpoTargets
192
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
193
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
194
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
195
+ install(FILES include/jpo/jpo.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/jpo)
196
+ install(FILES LICENSE.PoseLib DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/jpo)
197
+ install(EXPORT jpoTargets NAMESPACE jpo:: DESTINATION "${jpo_cmake_dir}")
198
+ export(EXPORT jpoTargets NAMESPACE jpo:: FILE "${CMAKE_CURRENT_BINARY_DIR}/jpoTargets.cmake")
199
+
200
+ # What jpoConfig.cmake must find again for the consumer.
201
+ get_target_property(jpo_type jpo TYPE)
202
+ set(JPO_CONFIG_STATIC OFF)
203
+ if(jpo_type STREQUAL "STATIC_LIBRARY")
204
+ set(JPO_CONFIG_STATIC ON)
205
+ endif()
206
+ set(JPO_CONFIG_THREADS OFF)
207
+ if(jpo_type STREQUAL "STATIC_LIBRARY" AND NOT EMSCRIPTEN)
208
+ set(JPO_CONFIG_THREADS ON)
209
+ endif()
210
+ set(JPO_CONFIG_CUDA OFF)
211
+ if(JPO_HAVE_CUDA AND jpo_type STREQUAL "STATIC_LIBRARY")
212
+ set(JPO_CONFIG_CUDA ON)
213
+ endif()
214
+ set(JPO_CONFIG_DAWN OFF)
215
+ if(JPO_HAVE_WEBGPU AND NOT EMSCRIPTEN)
216
+ set(JPO_CONFIG_DAWN ON)
217
+ set(JPO_CONFIG_THREADS ON) # Dawn's own package names Threads::Threads without finding it
218
+ set(JPO_CONFIG_DAWN_DIR "${Dawn_DIR}")
219
+ endif()
220
+ set(JPO_CONFIG_EMDAWNWEBGPU OFF)
221
+ if(JPO_HAVE_WEBGPU AND EMSCRIPTEN)
222
+ set(JPO_CONFIG_EMDAWNWEBGPU ON)
223
+ endif()
224
+ set(JPO_CONFIG_BACKENDS "${jpo_backends}")
225
+ foreach(location install build)
226
+ if(location STREQUAL "install")
227
+ set(out "${CMAKE_CURRENT_BINARY_DIR}/package/jpoConfig.cmake")
228
+ set(dest "${jpo_cmake_dir}")
229
+ else()
230
+ set(out "${CMAKE_CURRENT_BINARY_DIR}/jpoConfig.cmake")
231
+ set(dest "${CMAKE_CURRENT_BINARY_DIR}")
232
+ endif()
233
+ configure_package_config_file(cmake/jpoConfig.cmake.in "${out}" INSTALL_DESTINATION "${dest}")
234
+ endforeach()
235
+ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/jpoConfigVersion.cmake"
236
+ COMPATIBILITY SameMajorVersion)
237
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/package/jpoConfig.cmake"
238
+ "${CMAKE_CURRENT_BINARY_DIR}/jpoConfigVersion.cmake"
239
+ DESTINATION "${jpo_cmake_dir}")
240
+ endif()
241
+
242
+ # The WebAssembly module (jpo_wasm.js + .wasm) with web/jpo.js and the test page, side by side in
243
+ # <build>/web, ready to serve. Single-threaded; waits for the GPU through JSPI.
244
+ if(EMSCRIPTEN AND JPO_BUILD_WASM)
245
+ add_executable(jpo_wasm web/jpo_wasm.cpp)
246
+ target_include_directories(jpo_wasm PRIVATE src ${CMAKE_CURRENT_SOURCE_DIR})
247
+ target_link_libraries(jpo_wasm PRIVATE jpo)
248
+ set_target_properties(jpo_wasm PROPERTIES SUFFIX ".js" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/web")
249
+ target_link_options(jpo_wasm PRIVATE
250
+ -sJSPI
251
+ "-sJSPI_EXPORTS=jpow_create,jpow_relative,jpow_absolute"
252
+ "-sEXPORTED_FUNCTIONS=_malloc,_free,_jpow_backend_available,_jpow_create,_jpow_destroy,_jpow_relative,_jpow_absolute,_jpow_synth,_jpow_error,_jpow_set_route,_jpow_last_stats"
253
+ "-sEXPORTED_RUNTIME_METHODS=HEAPU8,HEAPU32,HEAPF64,UTF8ToString"
254
+ -sMODULARIZE
255
+ -sEXPORT_ES6
256
+ -sEXPORT_NAME=createJpo
257
+ -sENVIRONMENT=web
258
+ -sALLOW_MEMORY_GROWTH
259
+ -sMAXIMUM_MEMORY=4GB
260
+ -sSTACK_SIZE=1MB)
261
+ foreach(f jpo.js test.html bench.html demo.html demo.js benchmark.html)
262
+ add_custom_command(TARGET jpo_wasm POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
263
+ "${CMAKE_CURRENT_SOURCE_DIR}/web/${f}" "${CMAKE_CURRENT_BINARY_DIR}/web/${f}")
264
+ endforeach()
265
+ add_custom_command(TARGET jpo_wasm POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory
266
+ "${CMAKE_CURRENT_SOURCE_DIR}/web/samples" "${CMAKE_CURRENT_BINARY_DIR}/web/samples")
267
+ endif()
268
+
269
+ if(JPO_BUILD_CLI AND NOT EMSCRIPTEN)
270
+ add_executable(jpo_cli cli/main.cpp cli/bench.cpp)
271
+ set_target_properties(jpo_cli PROPERTIES OUTPUT_NAME jpo)
272
+ target_include_directories(jpo_cli PRIVATE src ${CMAKE_CURRENT_SOURCE_DIR})
273
+ target_link_libraries(jpo_cli PRIVATE jpo)
274
+ if(JPO_INSTALL)
275
+ install(TARGETS jpo_cli RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
276
+ endif()
277
+ endif()
278
+
279
+ # PoseLib: the reference tool and the parity tests. Test-only; the library does not use it.
280
+ set(jpo_poselib "${CMAKE_CURRENT_SOURCE_DIR}/third_party/poselib")
281
+ set(jpo_eigen "${CMAKE_CURRENT_SOURCE_DIR}/third_party/eigen")
282
+ if(NOT JPO_REFERENCE STREQUAL "OFF" AND NOT EMSCRIPTEN)
283
+ if(EXISTS "${jpo_poselib}/PoseLib/robust.cc" AND EXISTS "${jpo_eigen}/Eigen/Dense")
284
+ set(JPO_HAVE_REFERENCE ON)
285
+ elseif(JPO_REFERENCE STREQUAL "ON")
286
+ message(FATAL_ERROR "JPO_REFERENCE=ON but third_party/poselib or third_party/eigen is missing (tools/fetch_reference.sh)")
287
+ endif()
288
+ endif()
289
+ if(JPO_HAVE_REFERENCE)
290
+ file(GLOB_RECURSE poselib_sources "${jpo_poselib}/PoseLib/*.cc")
291
+ add_library(poselib_ref STATIC ${poselib_sources})
292
+ target_include_directories(poselib_ref SYSTEM PUBLIC "${jpo_poselib}" "${jpo_eigen}")
293
+ target_compile_options(poselib_ref PRIVATE -w)
294
+ add_executable(poselib_ref_tool tools/poselib_ref.cc)
295
+ set_target_properties(poselib_ref_tool PROPERTIES OUTPUT_NAME poselib_ref)
296
+ target_include_directories(poselib_ref_tool PRIVATE include ${CMAKE_CURRENT_SOURCE_DIR})
297
+ target_link_libraries(poselib_ref_tool PRIVATE poselib_ref Threads::Threads)
298
+ endif()
299
+
300
+ if(JPO_BUILD_TESTS AND NOT EMSCRIPTEN)
301
+ enable_testing()
302
+ # Solvers, cameras and refinement on generated data; the whole estimators against known poses.
303
+ add_executable(core_test tests/core_test.cpp)
304
+ target_include_directories(core_test PRIVATE src ${CMAKE_CURRENT_SOURCE_DIR})
305
+ target_link_libraries(core_test PRIVATE jpo)
306
+ add_test(NAME core COMMAND core_test)
307
+ # The float build of the kernels against the double build (PLAN.md, "Precision").
308
+ add_executable(precision_test tests/precision_test.cpp)
309
+ target_include_directories(precision_test PRIVATE src ${CMAKE_CURRENT_SOURCE_DIR})
310
+ target_link_libraries(precision_test PRIVATE jpo)
311
+ add_test(NAME precision COMMAND precision_test)
312
+ if(JPO_HAVE_REFERENCE)
313
+ # Each solver against PoseLib's on the same samples.
314
+ add_executable(parity_test tests/parity_test.cpp)
315
+ target_include_directories(parity_test PRIVATE src ${CMAKE_CURRENT_SOURCE_DIR})
316
+ target_link_libraries(parity_test PRIVATE jpo poselib_ref)
317
+ add_test(NAME poselib_parity COMMAND parity_test)
318
+ endif()
319
+ # A project outside this tree finds the installed package and solves a problem through it.
320
+ if(JPO_INSTALL)
321
+ add_test(NAME package
322
+ COMMAND ${CMAKE_COMMAND} "-DJPO_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}" "-DJPO_CONFIG=$<CONFIG>"
323
+ "-DJPO_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/tests/package"
324
+ "-DJPO_GENERATOR=${CMAKE_GENERATOR}"
325
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/tests/package/run.cmake")
326
+ endif()
327
+ # The incremental reconstruction test (needs just-ba; see tests/incremental/CMakeLists.txt).
328
+ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/incremental/CMakeLists.txt")
329
+ add_subdirectory(tests/incremental)
330
+ endif()
331
+ set(gpu_backends ${jpo_backends})
332
+ list(REMOVE_ITEM gpu_backends cpu)
333
+ if(gpu_backends)
334
+ # Each GPU backend against the float CPU build: the same samples, the same best hypothesis.
335
+ add_executable(backend_test tests/backend_test.cpp)
336
+ target_include_directories(backend_test PRIVATE src ${CMAKE_CURRENT_SOURCE_DIR})
337
+ target_link_libraries(backend_test PRIVATE jpo)
338
+ foreach(b CUDA METAL WEBGPU)
339
+ if(JPO_HAVE_${b})
340
+ target_compile_definitions(backend_test PRIVATE JPO_HAVE_${b}) # the internal factories (backend.h)
341
+ endif()
342
+ endforeach()
343
+ foreach(backend IN LISTS gpu_backends)
344
+ add_test(NAME ${backend}_vs_cpu COMMAND backend_test ${backend})
345
+ endforeach()
346
+ if(JPO_HAVE_WEBGPU)
347
+ add_executable(webgpu_shared_test tests/webgpu_shared_test.cpp)
348
+ target_link_libraries(webgpu_shared_test PRIVATE jpo)
349
+ add_test(NAME webgpu_shared_device COMMAND webgpu_shared_test)
350
+ endif()
351
+ endif()
352
+ endif()
353
+
354
+ # The Python module (bindings/python), after the tests so that its own test is registered with them.
355
+ if(JPO_BUILD_PYTHON AND NOT EMSCRIPTEN)
356
+ add_subdirectory(bindings/python)
357
+ endif()
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2020, Viktor Larsson
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.