Skip to content

Commit b811941

Browse files
committed
align consecutive assignments
1 parent cf97f1c commit b811941

44 files changed

Lines changed: 961 additions & 955 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.clang-format‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ BreakBeforeBraces: Attach
1010
AllowShortFunctionsOnASingleLine: Inline
1111
AllowShortIfStatementsOnASingleLine: Never
1212
AllowShortLoopsOnASingleLine: false
13+
AlignConsecutiveAssignments:
14+
Enabled: true
15+
AcrossEmptyLines: false
16+
AcrossComments: false
17+
AlignCompound: false
18+
PadOperators: true
1319
PointerAlignment: Middle
1420
ReferenceAlignment: Middle
1521
SortIncludes: false

‎robot_client/cpp/model_client.cpp‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <cstring>
66
#include <utility>
77

8-
namespace proto = robot_server::protocol;
8+
namespace proto = robot_server::protocol;
99
namespace sockets = robot_server::sockets;
1010

1111
namespace robot_server {
@@ -15,8 +15,8 @@ namespace {
1515
bool send_message(sockets::socket_handle fd, uint16_t op, uint32_t request_id, const std::vector<uint8_t> & payload,
1616
std::string & error) {
1717
proto::header h;
18-
h.op = op;
19-
h.request_id = request_id;
18+
h.op = op;
19+
h.request_id = request_id;
2020
h.payload_len = payload.size();
2121

2222
std::vector<uint8_t> header;
@@ -55,7 +55,7 @@ bool make_predict_request(const ModelObservation & obs, proto::predict_request &
5555
return false;
5656
}
5757

58-
req.task = obs.prompt;
58+
req.task = obs.prompt;
5959
req.state = obs.state;
6060
req.images.clear();
6161
req.images.reserve(obs.images.size());
@@ -75,11 +75,11 @@ bool make_predict_request(const ModelObservation & obs, proto::predict_request &
7575

7676
const size_t image_size = (size_t)stride * (size_t)src.height;
7777
proto::image_payload image;
78-
image.name = src.name.empty() ? "image" + std::to_string(i) : src.name;
78+
image.name = src.name.empty() ? "image" + std::to_string(i) : src.name;
7979
image.image_format = proto::image_raw_rgb_u8;
80-
image.width = src.width;
81-
image.height = src.height;
82-
image.channels = 3;
80+
image.width = src.width;
81+
image.height = src.height;
82+
image.channels = 3;
8383
image.stride_bytes = stride;
8484
image.data.resize(image_size);
8585
std::memcpy(image.data.data(), src.rgb_hwc_u8, image_size);
@@ -157,10 +157,10 @@ bool ModelClient::predict(const ModelObservation & obs, ModelResponse & response
157157
return false;
158158
}
159159

160-
response.chunk_size = resp.chunk_size;
161-
response.action_dim = resp.action_dim;
160+
response.chunk_size = resp.chunk_size;
161+
response.action_dim = resp.action_dim;
162162
response.actions_flat = std::move(resp.actions);
163-
response.metrics = std::move(resp.metrics);
163+
response.metrics = std::move(resp.metrics);
164164
return true;
165165
}
166166

@@ -177,7 +177,7 @@ bool ModelClient::call(uint16_t op, const std::vector<uint8_t> & request_payload
177177
}
178178

179179
const uint32_t request_id = next_request_id_++;
180-
bool ok = send_message(fd, op, request_id, request_payload, error);
180+
bool ok = send_message(fd, op, request_id, request_payload, error);
181181
proto::header response_header;
182182
if (ok) {
183183
ok = recv_message(fd, response_header, response_payload, error);

‎robot_client/cpp/model_client.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ namespace client {
1212

1313
struct ModelImage {
1414
const uint8_t * rgb_hwc_u8 = nullptr;
15-
uint32_t width = 0;
16-
uint32_t height = 0;
17-
uint32_t stride_bytes = 0;
18-
std::string name = "image";
15+
uint32_t width = 0;
16+
uint32_t height = 0;
17+
uint32_t stride_bytes = 0;
18+
std::string name = "image";
1919
};
2020

2121
struct ModelObservation {
@@ -48,7 +48,7 @@ class ModelClient {
4848
std::string & error);
4949

5050
std::string host_;
51-
uint16_t port_ = 5555;
51+
uint16_t port_ = 5555;
5252
uint32_t next_request_id_ = 1;
5353
};
5454

‎robot_client/examples/cpp/minimal_example.cpp‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,28 @@ std::vector<float> make_random_state(uint32_t dim) {
3737

3838
int main(int argc, char ** argv) {
3939
std::string host = "127.0.0.1";
40-
uint16_t port = 5555;
40+
uint16_t port = 5555;
4141
if (argc > 1) {
4242
host = argv[1];
4343
}
4444
if (argc > 2) {
4545
port = (uint16_t)std::stoi(argv[2]);
4646
}
4747

48-
const uint32_t width = 224;
49-
const uint32_t height = 224;
48+
const uint32_t width = 224;
49+
const uint32_t height = 224;
5050
std::vector<uint8_t> image = make_random_rgb_image(width, height);
51-
std::vector<float> state = make_random_state(6);
51+
std::vector<float> state = make_random_state(6);
5252

5353
client::ModelObservation obs;
5454
client::ModelImage camera;
55-
camera.name = "image";
56-
camera.rgb_hwc_u8 = image.data();
57-
camera.width = width;
58-
camera.height = height;
55+
camera.name = "image";
56+
camera.rgb_hwc_u8 = image.data();
57+
camera.width = width;
58+
camera.height = height;
5959
camera.stride_bytes = width * 3;
6060
obs.images.push_back(camera);
61-
obs.state = state;
61+
obs.state = state;
6262
obs.prompt = "grab the block.";
6363

6464
client::ModelClient model(host, port);

‎robot_server/model-server.cpp‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ struct server_args {
2626
std::string action_decoder_path;
2727
std::string state_proj_path;
2828
std::string action_expert_path;
29-
std::string task = "grab the block.";
30-
std::string host = "127.0.0.1";
31-
int port = 5555;
32-
int threads = 0;
33-
int n_batch = 512;
34-
int n_ctx = 2048;
35-
int noise_mode = SMOLVLA_NOISE_MODE_GAUSSIAN;
29+
std::string task = "grab the block.";
30+
std::string host = "127.0.0.1";
31+
int port = 5555;
32+
int threads = 0;
33+
int n_batch = 512;
34+
int n_ctx = 2048;
35+
int noise_mode = SMOLVLA_NOISE_MODE_GAUSSIAN;
3636
int64_t noise_seed = -1;
37-
int verbosity = 0;
37+
int verbosity = 0;
3838
};
3939

4040
static bool parse_model_type(const std::string & value, robotcpp::model_type & out) {
@@ -184,21 +184,21 @@ static bool parse_args(int argc, char ** argv, server_args & args) {
184184

185185
static robotcpp::model_args make_model_args(const server_args & args) {
186186
robotcpp::model_args model_args;
187-
model_args.type = args.model_type;
188-
model_args.threads = args.threads;
189-
model_args.verbosity = args.verbosity;
190-
model_args.llm_path = args.llm_path;
191-
model_args.mmproj_path = args.mmproj_path;
192-
model_args.vit_path = args.vit_path;
193-
model_args.tokenizer_path = args.tokenizer_path;
194-
model_args.state_path = args.state_path;
187+
model_args.type = args.model_type;
188+
model_args.threads = args.threads;
189+
model_args.verbosity = args.verbosity;
190+
model_args.llm_path = args.llm_path;
191+
model_args.mmproj_path = args.mmproj_path;
192+
model_args.vit_path = args.vit_path;
193+
model_args.tokenizer_path = args.tokenizer_path;
194+
model_args.state_path = args.state_path;
195195
model_args.action_decoder_path = args.action_decoder_path;
196-
model_args.state_proj_path = args.state_proj_path;
197-
model_args.action_expert_path = args.action_expert_path;
198-
model_args.n_batch = args.n_batch;
199-
model_args.n_ctx = args.n_ctx;
200-
model_args.noise_mode = args.noise_mode;
201-
model_args.noise_seed = args.noise_seed;
196+
model_args.state_proj_path = args.state_proj_path;
197+
model_args.action_expert_path = args.action_expert_path;
198+
model_args.n_batch = args.n_batch;
199+
model_args.n_ctx = args.n_ctx;
200+
model_args.noise_mode = args.noise_mode;
201+
model_args.noise_seed = args.noise_seed;
202202
return model_args;
203203
}
204204

‎robot_server/model_adapter.cpp‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ bool model_adapter::predict(const proto::predict_request & req, proto::predict_r
2222
obs.images.reserve(req.images.size());
2323
for (const proto::image_payload & src : req.images) {
2424
robotcpp::model_image image;
25-
image.name = src.name.empty() ? "image" : src.name;
26-
image.data = src.data.empty() ? nullptr : src.data.data();
27-
image.width = static_cast<int>(src.width);
28-
image.height = static_cast<int>(src.height);
29-
image.channels = static_cast<int>(src.channels);
25+
image.name = src.name.empty() ? "image" : src.name;
26+
image.data = src.data.empty() ? nullptr : src.data.data();
27+
image.width = static_cast<int>(src.width);
28+
image.height = static_cast<int>(src.height);
29+
image.channels = static_cast<int>(src.channels);
3030
image.stride_bytes = static_cast<int>(src.stride_bytes);
3131
obs.images.push_back(image);
3232
}
3333
obs.state = req.state;
34-
obs.task = req.task;
34+
obs.task = req.task;
3535

3636
robotcpp::model_result result;
3737
if (!model_->predict(obs, result, error)) {
@@ -40,11 +40,11 @@ bool model_adapter::predict(const proto::predict_request & req, proto::predict_r
4040

4141
resp.chunk_size = static_cast<uint32_t>(result.chunk_size);
4242
resp.action_dim = static_cast<uint32_t>(result.action_dim);
43-
resp.actions = std::move(result.actions);
43+
resp.actions = std::move(result.actions);
4444
resp.metrics.reserve(result.metrics.size());
4545
for (const robotcpp::model_metric & src : result.metrics) {
4646
proto::metric dst;
47-
dst.name = src.name;
47+
dst.name = src.name;
4848
dst.value = src.value;
4949
resp.metrics.push_back(std::move(dst));
5050
}

‎robot_server/model_adapter.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class model_adapter {
1717
explicit model_adapter(std::unique_ptr<robotcpp::Model> model);
1818
~model_adapter();
1919

20-
model_adapter(const model_adapter &) = delete;
20+
model_adapter(const model_adapter &) = delete;
2121
model_adapter & operator=(const model_adapter &) = delete;
2222

2323
bool predict(const robot_server::protocol::predict_request & req, robot_server::protocol::predict_response & resp,

‎robot_server/protocol.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ bool decode_predict_request(const std::vector<uint8_t> & payload, predict_reques
254254
req = predict_request{};
255255
reader r(payload.data(), payload.size());
256256
uint32_t image_count = 0;
257-
uint32_t state_dim = 0;
258-
uint32_t task_len = 0;
257+
uint32_t state_dim = 0;
258+
uint32_t task_len = 0;
259259

260260
if (!r.u32(image_count) || !r.u32(state_dim) || !r.u32(task_len)) {
261261
error = "short predict request";

‎robot_server/protocol.h‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
namespace robot_server {
99
namespace protocol {
1010

11-
static constexpr uint32_t k_magic = 0x414c5653u; // "SVLA" in little-endian bytes.
12-
static constexpr uint16_t k_version = 3;
13-
static constexpr uint16_t k_header_size = 32;
11+
static constexpr uint32_t k_magic = 0x414c5653u; // "SVLA" in little-endian bytes.
12+
static constexpr uint16_t k_version = 3;
13+
static constexpr uint16_t k_header_size = 32;
1414
static constexpr uint64_t k_default_max_payload = 256ull * 1024ull * 1024ull;
1515

1616
enum op : uint16_t {
17-
op_health = 1,
18-
op_reset = 2,
19-
op_predict = 3,
17+
op_health = 1,
18+
op_reset = 2,
19+
op_predict = 3,
2020
op_shutdown = 4,
2121
};
2222

2323
enum status : uint32_t {
24-
status_ok = 0,
25-
status_bad_request = 1,
26-
status_bad_magic = 2,
27-
status_bad_version = 3,
24+
status_ok = 0,
25+
status_bad_request = 1,
26+
status_bad_magic = 2,
27+
status_bad_version = 3,
2828
status_payload_too_big = 4,
29-
status_internal_error = 5,
29+
status_internal_error = 5,
3030
};
3131

3232
enum image_format : uint32_t {
@@ -35,24 +35,24 @@ enum image_format : uint32_t {
3535

3636
struct image_payload {
3737
uint32_t image_format = image_raw_rgb_u8;
38-
uint32_t width = 0;
39-
uint32_t height = 0;
40-
uint32_t channels = 0;
38+
uint32_t width = 0;
39+
uint32_t height = 0;
40+
uint32_t channels = 0;
4141
uint32_t stride_bytes = 0;
4242
std::string name;
4343
std::vector<uint8_t> data;
4444
};
4545

4646
struct header {
47-
uint32_t magic = k_magic;
48-
uint16_t version = k_version;
47+
uint32_t magic = k_magic;
48+
uint16_t version = k_version;
4949
uint16_t header_size = k_header_size;
50-
uint16_t op = 0;
51-
uint16_t flags = 0;
52-
uint32_t request_id = 0;
53-
uint32_t status = status_ok;
50+
uint16_t op = 0;
51+
uint16_t flags = 0;
52+
uint32_t request_id = 0;
53+
uint32_t status = status_ok;
5454
uint64_t payload_len = 0;
55-
uint32_t reserved = 0;
55+
uint32_t reserved = 0;
5656
};
5757

5858
struct metric {

‎robot_server/session.cpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <utility>
2121
#include <vector>
2222

23-
namespace proto = robot_server::protocol;
23+
namespace proto = robot_server::protocol;
2424
using clock_type = std::chrono::steady_clock;
2525

2626
namespace robot_server {
@@ -32,17 +32,17 @@ static double elapsed_ms(const clock_type::time_point & a, const clock_type::tim
3232

3333
static void add_metric(proto::predict_response & resp, const char * name, double value) {
3434
proto::metric metric;
35-
metric.name = name;
35+
metric.name = name;
3636
metric.value = value;
3737
resp.metrics.push_back(std::move(metric));
3838
}
3939

4040
static bool send_message(sockets::socket_handle fd, uint16_t op, uint32_t request_id, uint32_t status,
4141
const std::vector<uint8_t> & payload, std::string & error) {
4242
proto::header h;
43-
h.op = op;
44-
h.request_id = request_id;
45-
h.status = status;
43+
h.op = op;
44+
h.request_id = request_id;
45+
h.status = status;
4646
h.payload_len = payload.size();
4747

4848
std::vector<uint8_t> hdr;
@@ -124,8 +124,8 @@ bool handle_client(sockets::socket_handle fd, model_adapter & policy, std::mutex
124124
std::unique_lock<std::mutex> lock(predict_mutex);
125125
const double server_queue_ms = elapsed_ms(t_queue0, clock_type::now());
126126

127-
const auto t_predict0 = clock_type::now();
128-
const bool ok = policy.predict(req, resp, error);
127+
const auto t_predict0 = clock_type::now();
128+
const bool ok = policy.predict(req, resp, error);
129129
const double server_predict_ms = elapsed_ms(t_predict0, clock_type::now());
130130
lock.unlock();
131131

0 commit comments

Comments
 (0)