File size: 3,260 Bytes
67c4f10 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #include "parvulus_c_api.h"
#include "parvulus_engine.h"
#include <cstring>
extern "C" {
ParvulusHandle parvulus_create(int device_id) {
return new ParvulusEngine(device_id);
}
bool parvulus_load(
ParvulusHandle handle,
const char* weights_path,
const char* embeddings_path,
const char* scale_path
) {
if (!handle) return false;
ParvulusEngine* engine = static_cast<ParvulusEngine*>(handle);
bool ok = engine->load_weights(weights_path);
if (embeddings_path != nullptr && std::strlen(embeddings_path) > 0) {
ok = ok && engine->load_task_embeddings(embeddings_path);
}
if (scale_path != nullptr && std::strlen(scale_path) > 0) {
ok = ok && engine->load_action_scale(scale_path);
}
return ok;
}
bool parvulus_set_task_vector(ParvulusHandle handle, const float* task_vector) {
if (!handle || !task_vector) return false;
ParvulusEngine* engine = static_cast<ParvulusEngine*>(handle);
return engine->set_task_vector(task_vector);
}
bool parvulus_set_task_string(ParvulusHandle handle, const char* task_description) {
if (!handle || !task_description) return false;
ParvulusEngine* engine = static_cast<ParvulusEngine*>(handle);
return engine->set_task_string(task_description);
}
bool parvulus_predict_chunk(
ParvulusHandle handle,
const uint8_t* agent_img,
const uint8_t* wrist_img,
const char* task_description,
float* out_actions,
int num_euler_steps,
const float* custom_z0
) {
if (!handle) return false;
ParvulusEngine* engine = static_cast<ParvulusEngine*>(handle);
if (task_description != nullptr && std::strlen(task_description) > 0) {
return engine->predict_action_chunk(agent_img, wrist_img, task_description, out_actions, num_euler_steps, custom_z0);
} else {
return engine->predict_action_chunk(agent_img, wrist_img, out_actions, num_euler_steps, custom_z0);
}
}
bool parvulus_predict_chunk_with_vector(
ParvulusHandle handle,
const uint8_t* agent_img,
const uint8_t* wrist_img,
const float* task_vector,
float* out_actions,
int num_euler_steps,
const float* custom_z0
) {
if (!handle) return false;
ParvulusEngine* engine = static_cast<ParvulusEngine*>(handle);
return engine->predict_action_chunk_with_vector(agent_img, wrist_img, task_vector, out_actions, num_euler_steps, custom_z0);
}
bool parvulus_predict_chunk_with_emb(
ParvulusHandle handle,
const uint8_t* agent_img,
const uint8_t* wrist_img,
const float* text_embedding,
float* out_actions,
int num_euler_steps,
const float* custom_z0
) {
return parvulus_predict_chunk_with_vector(handle, agent_img, wrist_img, text_embedding, out_actions, num_euler_steps, custom_z0);
}
bool parvulus_register_task_embedding(
ParvulusHandle handle,
const char* task_description,
const float* text_embedding
) {
if (!handle || !task_description || !text_embedding) return false;
ParvulusEngine* engine = static_cast<ParvulusEngine*>(handle);
return engine->register_task_embedding(task_description, text_embedding);
}
void parvulus_destroy(ParvulusHandle handle) {
if (handle) {
delete static_cast<ParvulusEngine*>(handle);
}
}
}
|