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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
build-wasm/
.cache/
compile_commands.json
*.out.*
Expand All @@ -19,3 +20,5 @@ venv/
/resources/panda/*.pkl
src/vamp/_core/*.pyi
/.mypy_cache/
.DS_store
vamp-web/
28 changes: 28 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ option(VAMP_INSTALL_CPP_LIBRARY "Install VAMP C++ library (disable for Python wh
option(VAMP_BUILD_CPP_DEMO "Build VAMP C++ Demo Scripts" OFF)
option(VAMP_BUILD_OMPL_DEMO "Build VAMP C++ OMPL Integration Demo Scripts" OFF)
option(VAMP_OMPL_PATH "Search Path for OMPL Installation - Only Needed for Demo Script" "")
option(VAMP_BUILD_WASM "Build VAMP WebAssembly module" OFF)

if(VAMP_FORCE_CLANG)
find_program(CLANG "clang")
Expand Down Expand Up @@ -165,10 +166,37 @@ if(VAMP_BUILD_OMPL_DEMO)
endif()
endif()

# WebAssembly build
if(VAMP_BUILD_WASM)
include(EmscriptenBuild)

if(NOT VAMP_WASM_ROBOT_MODULES)
set(VAMP_WASM_ROBOT_MODULES panda fetch ur5)
set(VAMP_WASM_ROBOT_STRUCTS Panda Fetch UR5)
endif()

foreach(robot_name ROBOT_STRUCT IN ZIP_LISTS VAMP_WASM_ROBOT_MODULES VAMP_WASM_ROBOT_STRUCTS)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/impl/vamp/bindings/wasm/bindings.cc.in
${CMAKE_CURRENT_BINARY_DIR}/wasm/${robot_name}_wasm_bindings.cc
@ONLY
)

vamp_create_wasm_module(${robot_name}_wasm
${CMAKE_CURRENT_BINARY_DIR}/wasm/${robot_name}_wasm_bindings.cc
)

target_include_directories(${robot_name}_wasm PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/impl
)
endforeach()
endif()

# Print build configuration
message(STATUS "VAMP build configuration:")
message(STATUS " - C++ library: ON")
message(STATUS " - Install C++ library: ${VAMP_INSTALL_CPP_LIBRARY}")
message(STATUS " - Python bindings: ${VAMP_BUILD_PYTHON_BINDINGS}")
message(STATUS " - C++ demos: ${VAMP_BUILD_CPP_DEMO}")
message(STATUS " - OMPL demos: ${VAMP_BUILD_OMPL_DEMO}")
message(STATUS " - WASM module: ${VAMP_BUILD_WASM}")
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ See the `environment.yaml` file for a basic environment, and see `docker/ubuntu2
We currently support x86 CPUs (e.g., Intel, AMD) with the [AVX2 vector instruction set](https://en.wikipedia.org/wiki/Advanced_Vector_Extensions) and ARM CPUs (e.g., Raspberry Pi, Mac M1) with [NEON](https://en.wikipedia.org/wiki/ARM_architecture_family#Advanced_SIMD_(Neon)).
Please see the `docker/` folder for reference installation procedures.

### WebAssembly (WASM)

VAMP can be compiled to WebAssembly for use in web browsers via [Emscripten](https://emscripten.org/).
The WASM build uses 128-bit SIMD instructions.

#### Building WASM Modules

First, install Emscripten.
Then build the WASM modules:
```bash
cd vamp
emcmake cmake -Bbuild-wasm -DCMAKE_BUILD_TYPE=Release -DVAMP_BUILD_WASM=ON
cmake --build build-wasm
```

This produces `{robot}_wasm.js` and `{robot}_wasm.wasm` files in `build-wasm/wasm/` for each robot (by default: `panda`, `fetch`, `ur5`).

### Using Clang instead of GCC
You can force the use of Clang instead of GCC for compiling VAMP by uncommenting the line at the bottom of the `pyproject.toml` (or setting the corresponding CMake variable for C++ builds):
```toml
Expand Down
5 changes: 4 additions & 1 deletion cmake/CompilerSettings.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Allow users to override VAMP_ARCH (e.g., for Docker builds targeting different hardware)
if(NOT DEFINED VAMP_ARCH)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
if(EMSCRIPTEN)
# WebAssembly with SIMD128 support
set(VAMP_ARCH "-msimd128")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
# Need explicit AVX2 for some MacOS clang versions
set(VAMP_ARCH "-march=native -mavx2")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
Expand Down
22 changes: 20 additions & 2 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
find_package(Eigen3 REQUIRED NO_MODULE)
if(EMSCRIPTEN)
# Fetch Eigen header-only library for WASM builds
# Emscripten doesn't have access to system packages
CPMAddPackage(
NAME Eigen3
VERSION 3.4.0
URL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
DOWNLOAD_ONLY YES
)
if(Eigen3_ADDED)
add_library(Eigen3::Eigen INTERFACE IMPORTED)
set_target_properties(Eigen3::Eigen PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${Eigen3_SOURCE_DIR}>"
)
endif()
else()
find_package(Eigen3 REQUIRED NO_MODULE)
endif()

CPMAddPackage("gh:kavrakilab/nigh#97130999440647c204e0265d05a997dbd8da4e70")
add_library(nigh INTERFACE)
Expand Down Expand Up @@ -31,7 +48,8 @@ if(VAMP_INSTALL_CPP_LIBRARY)
endif()

# SIMDxorshift for x86_64 systems (includes macOS Intel and Linux x86_64)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
# Explicitly exclude Emscripten since it doesn't support AVX
if(NOT EMSCRIPTEN AND (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64"))
CPMAddPackage("gh:lemire/SIMDxorshift#857c1a01df53cf1ee1ae8db3238f0ef42ef8e490")

if(SIMDxorshift_SOURCE_DIR)
Expand Down
48 changes: 48 additions & 0 deletions cmake/EmscriptenBuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
if(NOT EMSCRIPTEN)
message(FATAL_ERROR "EmscriptenBuild.cmake requires Emscripten toolchain.")
endif()

message(STATUS "Configuring VAMP for WebAssembly build")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msimd128")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msimd128")

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -flto")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -flto")

set(VAMP_DISABLE_SIMDXORSHIFT ON CACHE BOOL "Disable SIMDxorshift for WASM build" FORCE)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")

set(VAMP_WASM_OUTPUT_NAME "vamp" CACHE STRING "Output name for WASM module")

set(VAMP_WASM_LINK_FLAGS
"-lembind"
"-fexceptions"
"-sALLOW_MEMORY_GROWTH=1"
"-sINITIAL_MEMORY=64MB"
"-sMAXIMUM_MEMORY=512MB"
"-sEXPORTED_RUNTIME_METHODS=['ccall','cwrap']"
"-sMODULARIZE=1"
"-sEXPORT_ES6=1"
"-sENVIRONMENT=web"
"-sWASM_BIGINT=1"
)
string(JOIN " " VAMP_WASM_LINK_FLAGS_STR ${VAMP_WASM_LINK_FLAGS})

function(vamp_create_wasm_module TARGET_NAME)
add_executable(${TARGET_NAME} ${ARGN})

target_link_libraries(${TARGET_NAME} PRIVATE vamp_cpp)

set_target_properties(${TARGET_NAME} PROPERTIES
LINK_FLAGS "${VAMP_WASM_LINK_FLAGS_STR}"
SUFFIX ".js"
)

set_target_properties(${TARGET_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/wasm"
)

message(STATUS "WASM target '${TARGET_NAME}' configured")
endfunction()
10 changes: 5 additions & 5 deletions cmake/Python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ if(VAMP_BUILD_PYTHON_BINDINGS)
list(JOIN VAMP_ROBOT_QUOTED ", " VAMP_ROBOT_NAMES)

configure_file(
src/impl/vamp/bindings/init.hh.in
src/impl/vamp/bindings/python/init.hh.in
${CMAKE_CURRENT_BINARY_DIR}/vamp_python_init.hh
@ONLY
)

configure_file(
src/impl/vamp/bindings/python.cc.in
src/impl/vamp/bindings/python/python.cc.in
${CMAKE_CURRENT_BINARY_DIR}/python.cc
@ONLY
)

list(APPEND VAMP_EXT_SOURCES
src/impl/vamp/bindings/environment.cc
src/impl/vamp/bindings/settings.cc
src/impl/vamp/bindings/python/environment.cc
src/impl/vamp/bindings/python/settings.cc
${CMAKE_CURRENT_BINARY_DIR}/python.cc
)
foreach(robot_name robot_struct IN ZIP_LISTS VAMP_ROBOT_MODULES VAMP_ROBOT_STRUCTS)
configure_file(
src/impl/vamp/bindings/robot.cc.in
src/impl/vamp/bindings/python/robot.cc.in
${CMAKE_CURRENT_BINARY_DIR}/${robot_name}.cc
@ONLY
)
Expand Down
12 changes: 5 additions & 7 deletions resources/panda/meshes/visual/link5.mtl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Blender MTL File: 'None'
# Material Count: 3
# Blender 4.4.3 MTL File: 'None'
# www.blender.org

newmtl Part__Feature_002_004_003.002
Ns -1.960784
Ns 1000.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.015625 0.015625 0.015625
Ke 0.000000 0.000000 0.000000
Ni 1.000000
Expand All @@ -13,9 +12,8 @@ illum 2
map_Kd colors.png

newmtl Shell001_001_001_003.002
Ns -1.960784
Ns 1000.000000
Ka 1.000000 1.000000 1.000000
Kd 0.250000 0.250000 0.250000
Ks 0.015625 0.015625 0.015625
Ke 0.000000 0.000000 0.000000
Ni 1.000000
Expand All @@ -24,7 +22,7 @@ illum 2
map_Kd colors.png

newmtl Shell_001_001_003.002
Ns -1.960784
Ns 1000.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.015625 0.015625 0.015625
Expand Down
Loading
Loading