Description
Some host programs like the nnlib tests expect function calls that automatically open the remote interface. e.g.
hexagon_nn_config();
hexagon_nn_init(&graph);
In HexagonRPC, the details of the opening and closing are much more exposed:
fd = hexagonrpc_fd_from_env();
remotectl_open(fd, strlen("hexagon_nn") + 1, "hexagon_nn",
&handle, &dlerr,
256, err);
ctx = fastrpc_create_context(fd, handle);
hexagon_nn_config(ctx);
hexagon_nn_init(ctx, &graph);
I like how all of the ioctls are called from the same va_args function, but we need better convenience functions that can remember dynamic handles throughout the duration of the program, like with dynamic linkers.
The interface definitions are currently defined with function-like macros so each remote interface can be in the same file (hexagonrpcd/interfaces/*.def
), but that leads to awkward usage:
HEXAGONRPC_DEFINE_REMOTE_METHOD3(10, hexagon_nn_getlog, false, // bool calculated manually that specifies if there's a primary output buffer (i.e. zero after the delimiter)
0, HEXAGONRPC_DELIMITER, 1) // in and out parameters, in the same array, delimited by a special value
There can only be one array if the remote methods are defined by a function-like macro.
Splitting the interfaces into more files can improve this.
hexagon_nn.c
:
static uint32_t handle_hexagon_nn = 0;
static const uint32_t hexagon_nn_getlog_in[] = { 0 };
static const uint32_t hexagon_nn_getlog_out[] = { 1 };
const struct hrpc_method_def_interp3 hexagon_nn_getlog_def = {
.msg_id = 10,
.has_prim_out = false,
.n_in = sizeof(hexagon_nn_getlog_in) / sizeof(*hexagon_nn_getlog_in),
.in = hexagon_nn_getlog_in,
.n_out = sizeof(hexagon_nn_getlog_out) / sizeof(*hexagon_nn_getlog_out),
.out = hexagon_nn_getlog_out,
};
struct fastrpc_context *open_hexagon_nn()
{
static struct fastrpc_context *ctx = NULL;
int fd;
if (!ctx) {
fd = hexagonrpc_fd_from_env();
ctx = hexagonrpc_open(fd, "hexagon_nn");
}
return ctx;
}
hexagon_nn.h
:
extern const struct hrpc_method_def_interp3 hexagon_nn_getlog_def;
static inline int hexagon_nn_getlog(
uint32_t id,
uint32_t size, char *buf)
{
struct fastrpc_context *ctx = open_hexagon_nn();
return hexagonrpc(&hexagon_nn_getlog_def, ctx, id, size, buf);
}