11cmake_minimum_required (VERSION 3.16 )
22project (robotcpp VERSION 0.1.0 LANGUAGES C CXX )
33
4+ include (CTest )
5+
46option (ROBOT_CPP_BUILD_ROBOT_SERVER "Build model-server target" ON )
57option (ROBOT_CPP_BUILD_MODEL_CLI "Build model-cli target" OFF )
68option (ROBOT_CPP_BUILD_ROBOT_CLIENT "Build C++ robot client targets" OFF )
9+ option (ROBOT_CPP_BUILD_STARVLA "Build the StarVLA runtime (requires llama.cpp overlay)" OFF )
710
811set (CMAKE_CXX_STANDARD 17)
912set (CMAKE_CXX_STANDARD_REQUIRED ON )
@@ -12,6 +15,27 @@ set(CMAKE_CXX_EXTENSIONS OFF)
1215if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR } /third_party/llama.cpp/CMakeLists.txt" )
1316 message (FATAL_ERROR "third_party/llama.cpp is required; run `git submodule update --init --recursive`" )
1417endif ()
18+ if (ROBOT_CPP_BUILD_STARVLA)
19+ file (READ
20+ "${CMAKE_CURRENT_SOURCE_DIR } /third_party/llama.cpp/tools/mtmd/models/qwen3vl.cpp"
21+ ROBOT_CPP_QWEN3VL_MTMD_SOURCE )
22+ file (READ
23+ "${CMAKE_CURRENT_SOURCE_DIR } /third_party/llama.cpp/include/llama.h"
24+ ROBOT_CPP_LLAMA_PUBLIC_HEADER )
25+ string (FIND "${ROBOT_CPP_QWEN3VL_MTMD_SOURCE} "
26+ "FFN_GELU_ERF" ROBOT_CPP_QWEN3VL_PARITY_PATCH_INDEX)
27+ string (FIND "${ROBOT_CPP_LLAMA_PUBLIC_HEADER} "
28+ "llama_set_backend_native_graphs_enabled" ROBOT_CPP_LLAMA_GRAPH_PATCH_INDEX)
29+ if (ROBOT_CPP_QWEN3VL_PARITY_PATCH_INDEX EQUAL -1 OR
30+ ROBOT_CPP_LLAMA_GRAPH_PATCH_INDEX EQUAL -1)
31+ message (FATAL_ERROR
32+ "StarVLA requires the pinned llama.cpp overlay. Run "
33+ "`./tools/apply_patches.sh` from the repository root, "
34+ "then configure again." )
35+ endif ()
36+ unset (ROBOT_CPP_QWEN3VL_MTMD_SOURCE)
37+ unset (ROBOT_CPP_LLAMA_PUBLIC_HEADER)
38+ endif ()
1539set (LLAMA_BUILD_COMMON ON CACHE BOOL "" FORCE )
1640set (LLAMA_BUILD_TOOLS OFF CACHE BOOL "" FORCE )
1741set (LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
@@ -20,7 +44,16 @@ add_subdirectory(third_party/llama.cpp EXCLUDE_FROM_ALL)
2044if (NOT TARGET ggml OR NOT TARGET llama)
2145 message (FATAL_ERROR "llama.cpp must provide ggml and llama targets" )
2246endif ()
23-
47+ if (ROBOT_CPP_BUILD_STARVLA)
48+ # mtmd normally inherits this variable when llama.cpp builds all tools.
49+ if (NOT LLAMA_INSTALL_VERSION)
50+ set (LLAMA_INSTALL_VERSION ${PROJECT_VERSION } )
51+ endif ()
52+ add_subdirectory (third_party/llama.cpp/tools/mtmd EXCLUDE_FROM_ALL )
53+ if (NOT TARGET mtmd)
54+ message (FATAL_ERROR "llama.cpp must provide the mtmd target for Qwen-VL" )
55+ endif ()
56+ endif ()
2457set (ROBOT_CPP_LLAMA_INCLUDE_DIRS
2558 ${CMAKE_CURRENT_SOURCE_DIR } /third_party/llama.cpp
2659 ${CMAKE_CURRENT_SOURCE_DIR } /third_party/llama.cpp/include
@@ -30,14 +63,29 @@ set(ROBOT_CPP_LLAMA_INCLUDE_DIRS
3063)
3164
3265set (SMOLVLA_DIR ${CMAKE_CURRENT_SOURCE_DIR } /src/models/smolvla)
66+ set (STARVLA_DIR ${CMAKE_CURRENT_SOURCE_DIR } /src/models/starvla)
3367set (ROBOT_SERVER_DIR ${CMAKE_CURRENT_SOURCE_DIR } /robot_server)
3468set (ROBOT_CLIENT_DIR ${CMAKE_CURRENT_SOURCE_DIR } /robot_client)
3569
36- add_library (smolvla_runtime STATIC
70+ add_library (robotcpp_model_common STATIC
3771 src/models/ggml_backend.cpp
3872 src/models/ggml_backend.h
3973 src/models/gguf_loader.cpp
4074 src/models/gguf_loader.h
75+ src/models/model_type.cpp
76+ )
77+ target_include_directories (robotcpp_model_common
78+ PUBLIC
79+ ${CMAKE_CURRENT_SOURCE_DIR } /src
80+ ${ROBOT_CPP_LLAMA_INCLUDE_DIRS}
81+ )
82+ target_link_libraries (robotcpp_model_common PUBLIC ggml )
83+ target_compile_features (robotcpp_model_common PUBLIC cxx_std_17 )
84+ if (NOT MSVC )
85+ target_compile_options (robotcpp_model_common PRIVATE -Wno-cast-qual )
86+ endif ()
87+
88+ add_library (smolvla_runtime STATIC
4189 ${SMOLVLA_DIR} /smolvla_engine.cpp
4290 ${SMOLVLA_DIR} /smolvla_engine.h
4391 ${SMOLVLA_DIR} /state_proj.cpp
@@ -53,17 +101,13 @@ target_include_directories(smolvla_runtime
53101 ${SMOLVLA_DIR}
54102 ${ROBOT_CPP_LLAMA_INCLUDE_DIRS}
55103)
56- target_link_libraries (smolvla_runtime PUBLIC ggml llama )
104+ target_link_libraries (smolvla_runtime PUBLIC robotcpp_model_common llama )
57105target_compile_features (smolvla_runtime PUBLIC cxx_std_17 )
58106if (NOT MSVC )
59107 target_compile_options (smolvla_runtime PRIVATE -Wno-cast-qual )
60108endif ()
61109
62110add_library (pi0_engine STATIC
63- src/models/ggml_backend.cpp
64- src/models/ggml_backend.h
65- src/models/gguf_loader.cpp
66- src/models/gguf_loader.h
67111 src/models/pi0/types.h
68112 src/models/pi0/action.cpp
69113 src/models/pi0/action.h
@@ -87,13 +131,65 @@ target_include_directories(pi0_engine
87131 ${CMAKE_CURRENT_SOURCE_DIR } /src
88132 ${ROBOT_CPP_LLAMA_INCLUDE_DIRS}
89133)
90- target_link_libraries (pi0_engine PUBLIC ggml llama )
134+ target_link_libraries (pi0_engine PUBLIC robotcpp_model_common llama )
91135target_compile_features (pi0_engine PUBLIC cxx_std_17 )
92136if (NOT MSVC )
93137 target_compile_options (pi0_engine PRIVATE -Wno-cast-qual )
94138endif ()
95139
140+ if (ROBOT_CPP_BUILD_STARVLA)
141+ add_library (starvla_runtime STATIC
142+ ${STARVLA_DIR} /fast_codec.cpp
143+ ${STARVLA_DIR} /fast_codec.h
144+ ${STARVLA_DIR} /fast_policy.cpp
145+ ${STARVLA_DIR} /fast_policy.h
146+ ${STARVLA_DIR} /groot_policy.cpp
147+ ${STARVLA_DIR} /groot_policy.h
148+ ${STARVLA_DIR} /groot_prompt.cpp
149+ ${STARVLA_DIR} /groot_prompt.h
150+ ${STARVLA_DIR} /normalization.cpp
151+ ${STARVLA_DIR} /normalization.h
152+ ${STARVLA_DIR} /oft_image_preprocess.cpp
153+ ${STARVLA_DIR} /oft_image_preprocess.h
154+ ${STARVLA_DIR} /oft_prompt.cpp
155+ ${STARVLA_DIR} /oft_prompt.h
156+ ${STARVLA_DIR} /oft_policy.cpp
157+ ${STARVLA_DIR} /oft_policy.h
158+ ${STARVLA_DIR} /pi_policy.cpp
159+ ${STARVLA_DIR} /pi_policy.h
160+ ${STARVLA_DIR} /pi_v3_policy.cpp
161+ ${STARVLA_DIR} /pi_v3_policy.h
162+ ${STARVLA_DIR} /policy_gguf.h
163+ ${STARVLA_DIR} /qwen3vl_bridge.cpp
164+ ${STARVLA_DIR} /qwen3vl_bridge.h
165+ ${STARVLA_DIR} /starvla_engine.cpp
166+ ${STARVLA_DIR} /starvla_engine.h
167+ third_party/llama.cpp/examples/gguf-hash/deps/sha256/sha256.c
168+ )
169+ target_include_directories (starvla_runtime
170+ PUBLIC
171+ ${CMAKE_CURRENT_SOURCE_DIR } /src
172+ ${ROBOT_CPP_LLAMA_INCLUDE_DIRS}
173+ PRIVATE
174+ ${CMAKE_CURRENT_SOURCE_DIR } /third_party/llama.cpp/vendor
175+ ${CMAKE_CURRENT_SOURCE_DIR } /third_party/llama.cpp/examples/gguf-hash/deps
176+ ${CMAKE_CURRENT_SOURCE_DIR } /third_party/llama.cpp/examples/gguf-hash/deps/sha256
177+ )
178+ target_link_libraries (starvla_runtime PUBLIC robotcpp_model_common llama mtmd )
179+ target_compile_features (starvla_runtime PUBLIC cxx_std_17 )
180+ if (GGML_CUDA)
181+ enable_language (CUDA )
182+ target_sources (starvla_runtime PRIVATE ${STARVLA_DIR} /qwen_bf16_round_cuda.cu )
183+ target_compile_definitions (starvla_runtime PRIVATE ROBOTCPP_STARVLA_CUDA=1 )
184+ set_property (TARGET starvla_runtime PROPERTY CUDA_STANDARD 17)
185+ endif ()
186+ if (NOT MSVC )
187+ target_compile_options (starvla_runtime PRIVATE -Wno-cast-qual )
188+ endif ()
189+ endif ()
190+
96191add_library (robotcpp STATIC
192+ src/models/argument_parse.h
97193 src/models/model.h
98194 src/models/model_factory.cpp
99195 src/models/pi0/pi0_model.cpp
@@ -108,6 +204,19 @@ target_include_directories(robotcpp
108204)
109205target_link_libraries (robotcpp PUBLIC smolvla_runtime pi0_engine )
110206target_compile_features (robotcpp PUBLIC cxx_std_17 )
207+ if (ROBOT_CPP_BUILD_STARVLA)
208+ target_sources (robotcpp PRIVATE
209+ ${STARVLA_DIR} /starvla_model.cpp
210+ ${STARVLA_DIR} /starvla_model.h )
211+ target_link_libraries (robotcpp PUBLIC starvla_runtime )
212+ target_compile_definitions (robotcpp PUBLIC ROBOT_CPP_BUILD_STARVLA=1 )
213+ endif ()
214+
215+ if (BUILD_TESTING AND ROBOT_CPP_BUILD_STARVLA)
216+ add_executable (robotcpp-starvla-model-test tests/starvla/model_test.cpp )
217+ target_link_libraries (robotcpp-starvla-model-test PRIVATE robotcpp )
218+ add_test (NAME robotcpp-starvla-model-test COMMAND robotcpp-starvla-model-test )
219+ endif ()
111220
112221if (ROBOT_CPP_BUILD_ROBOT_SERVER OR ROBOT_CPP_BUILD_ROBOT_CLIENT)
113222 add_library (robot_server_common STATIC
@@ -139,6 +248,7 @@ if(ROBOT_CPP_BUILD_ROBOT_CLIENT)
139248 set_target_properties (model-cpp-client-example PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR } /bin)
140249 target_link_libraries (model-cpp-client-example PRIVATE model_client_cpp )
141250 target_compile_features (model-cpp-client-example PRIVATE cxx_std_17 )
251+
142252endif ()
143253
144254if (ROBOT_CPP_BUILD_ROBOT_SERVER)
@@ -165,7 +275,6 @@ if(ROBOT_CPP_BUILD_ROBOT_SERVER)
165275 )
166276 target_link_libraries (model-server PRIVATE robot_server_core robotcpp )
167277 target_compile_features (model-server PRIVATE cxx_std_17 )
168-
169278 add_executable (smolvla-raw-predict ${ROBOT_SERVER_DIR} /test/smolvla_raw_predict.cpp )
170279 set_target_properties (smolvla-raw-predict PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR } /bin)
171280 target_include_directories (smolvla-raw-predict PRIVATE ${CMAKE_CURRENT_SOURCE_DIR } /src ${SMOLVLA_DIR} )
0 commit comments