File size: 4,162 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | #pragma once
/**
* @file parvulus_c_api.h
* @brief Pure C ABI interface for high-frequency PARVULUS robot policy inference.
*
* Standalone native CUDA/cuBLAS runtime with ZERO PyTorch, LibTorch, or Python dependencies.
* Designed for high-frequency (136 Hz) physical robot manipulation loops (ROS 2, FCI, MuJoCo).
*/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void* ParvulusHandle;
/**
* @brief Initializes a PARVULUS engine context on the designated CUDA device.
* @param device_id CUDA device index (0, 1, 2, ...).
* @return Opaque handle to the initialized engine, or NULL on error.
*/
ParvulusHandle parvulus_create(int device_id);
/**
* @brief Loads model weights, optional task language representations, and normalization scales.
* @param handle Valid ParvulusHandle.
* @param weights_path Path to flat model weights binary (parvulus_model_weights.bin).
* @param embeddings_path Path to pre-cached task language embeddings binary (optional, can be NULL).
* @param scale_path Path to 7-DoF action scale binary (optional, can be NULL).
* @return true if loading succeeded, false otherwise.
*/
bool parvulus_load(
ParvulusHandle handle,
const char* weights_path,
const char* embeddings_path,
const char* scale_path
);
/**
* @brief Sets the active 256-dim task conditioning vector on GPU VRAM.
* All subsequent chunk predictions will use this vector until updated.
*
* @param handle Valid ParvulusHandle.
* @param task_vector Array of 256 float32 values.
* @return true if successfully uploaded to GPU, false otherwise.
*/
bool parvulus_set_task_vector(ParvulusHandle handle, const float* task_vector);
/**
* @brief Sets the active task conditioning from a pre-cached task description string.
*
* @param handle Valid ParvulusHandle.
* @param task_description String matching an entry in task_embeddings.bin.
* @return true if found and set, false if string was not in cache.
*/
bool parvulus_set_task_string(ParvulusHandle handle, const char* task_description);
/**
* @brief Generates an 8-step continuous action chunk from dual 256x256 RGB observations.
*
* @param handle Valid ParvulusHandle.
* @param agent_img Contiguous [256, 256, 3] uint8 RGB camera frame (agent POV).
* @param wrist_img Contiguous [256, 256, 3] uint8 RGB camera frame (eye-in-hand POV).
* @param task_description Optional task string (pass NULL to use active task conditioning vector).
* @param out_actions Output buffer of length 56 (8 steps x 7 DoF: dx, dy, dz, drx, dry, drz, gripper).
* @param num_euler_steps Number of ODE flow integration steps (typically 4 or 10).
* @param custom_z0 Optional initial noise buffer [56 floats] for deterministic testing (NULL for random).
* @return true if prediction succeeded, false on error.
*/
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
);
/**
* @brief Predicts an action chunk directly using a 256-dim task conditioning vector.
* Updates the active task vector on GPU and generates the action chunk.
*/
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
);
/**
* @brief Alias for parvulus_predict_chunk_with_vector.
*/
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
);
/**
* @brief Registers or updates a task description string and its 256-dim embedding dynamically in memory.
*/
bool parvulus_register_task_embedding(
ParvulusHandle handle,
const char* task_description,
const float* text_embedding
);
/**
* @brief Destroys engine instance and releases all GPU allocations.
*/
void parvulus_destroy(ParvulusHandle handle);
#ifdef __cplusplus
}
#endif
|