static inline uint64_t
NPUBIN_META_TOTAL_SIZE (uint64_t magiccode) {
uint64_t size_extended = NPUBIN_META_EXTENDED_SIZE (magiccode);
- assert (size_extended <=
- UINT8_MAX * NPUBIN_META_SIZE); /** sanity check for svace */
+ assert (size_extended <= UINT8_MAX * NPUBIN_META_SIZE); /** sanity check for svace */
return size_extended + NPUBIN_META_SIZE;
}
#define NPUBIN_MAGICCODE (0x53524E5055000000ULL) /* ASCII hex for 'SRNPU' */
#define NPUBIN_VERSION_MAX (3)
#define NPUBIN_VERSION(magiccode) ((magiccode) &0xFFULL)
-#define CHECK_NPUBIN(magiccode) \
- (((magiccode) & ~0xFFFFFFULL) == NPUBIN_MAGICCODE)
+#define CHECK_NPUBIN(magiccode) (((magiccode) & ~0xFFFFFFULL) == NPUBIN_MAGICCODE)
/* npubinfmt npu_version macros */
#define NPU_VERSION_MAJOR(npu_version) (((npu_version) &0x000000FFULL))
/* Compile-time assert. From http://www.pixelbeat.org/programming/gcc/static_assert.html */
#define ASSERT_CONCAT_(a, b) a##b
#define ASSERT_CONCAT(a, b) ASSERT_CONCAT_ (a, b)
-#define ct_assert(e) \
- enum { ASSERT_CONCAT (assert_line_, __LINE__) = 1 / (!!(e)) }
+#define ct_assert(e) enum { ASSERT_CONCAT (assert_line_, __LINE__) = 1 / (!!(e)) }
ct_assert (sizeof (npubin_meta) == NPUBIN_META_SIZE);
/**< alias for backward-compatibility */
DATA_LAYOUT_TRIV2, /**< customized layout for TRIV2 (based on NHWC) */
DATA_LAYOUT_MODEL, /**< use the same data layout specified in model metadata */
- DATA_LAYOUT_RAW, /**< any raw data. npu-engine does not care about its layout */
+ DATA_LAYOUT_RAW, /**< any raw data. npu-engine does not care about its layout */
} data_layout;
/**
* Each generic buffer can have different buffer types.
*/
typedef struct {
- uint32_t num_buffers; /**< The number of tensors in this "buffer" */
- generic_buffer
- bufs[NPU_TENSOR_CARDINALITY_MAX]; /**< Buffer struct for each tensor */
+ uint32_t num_buffers; /**< The number of tensors in this "buffer" */
+ generic_buffer bufs[NPU_TENSOR_CARDINALITY_MAX]; /**< Buffer struct for each tensor */
} generic_buffers;
/**
* @detail The callback function has the responsibility to free the given
* output buffer (output) when its type is BUFFER_MAPPED.
*/
-typedef void (*npuOutputNotify) (output_buffers *output, int req_id,
- void *data);
+typedef void (*npuOutputNotify) (output_buffers *output, int req_id, void *data);
/**
* @brief deprecated mode.
* third-party hardware.
*/
typedef enum {
- NPU_INTERRUPT =
- 0, /**< interrupt: moderate latency but save CPU usage (default) */
- NPU_POLLING = 1, /**< polling: consume CPU usage but achieve low latency */
+ NPU_INTERRUPT = 0, /**< interrupt: moderate latency but save CPU usage (default) */
+ NPU_POLLING = 1, /**< polling: consume CPU usage but achieve low latency */
} npu_notimode;
/**
/**
* @brief Describes the supported NPU Scheduler (in kernel modules)
*/
-typedef enum {
- NPU_SCHEDULER_UNKNOWN = 0,
- NPU_SCHEDULER_SR,
- NPU_SCHEDULER_VD
-} npu_scheduler;
+typedef enum { NPU_SCHEDULER_UNKNOWN = 0, NPU_SCHEDULER_SR, NPU_SCHEDULER_VD } npu_scheduler;
/** @brief optional parameter for npu scheduler */
typedef void *npu_scheduler_param;
* @brief Description of npu device status
*/
typedef enum {
- NPU_ERROR =
- 0, /**< The NPU is not available for now (check the log file for details) */
- NPU_READY =
- 1, /**< The NPU is available but the request can be delayed due to others */
- NPU_IDLE =
- 2, /**< The NPU is available and there's no active request currently */
+ NPU_ERROR = 0, /**< The NPU is not available for now (check the log file for details) */
+ NPU_READY = 1, /**< The NPU is available but the request can be delayed due to others */
+ NPU_IDLE = 2, /**< The NPU is available and there's no active request currently */
} npu_status;
/**
* @note this mode will decide which input service performs the inference of a model.
*/
typedef enum {
- NPUINPUT_STOP = 0, /**< Stop Processing */
- NPUINPUT_INTERNAL_CAM =
- 1, /**< Let ADSP preprocess image stream from MIPI and send it to
+ NPUINPUT_STOP = 0, /**< Stop Processing */
+ NPUINPUT_INTERNAL_CAM = 1, /**< Let ADSP preprocess image stream from MIPI and send it to
NPU-core to be processed with the given model.
(not supported yet) */
- NPUINPUT_I2S_MIC =
- 2, /**< ASR mode with on-chip internal I2S. modelid is ignored.
+ NPUINPUT_I2S_MIC = 2, /**< ASR mode with on-chip internal I2S. modelid is ignored.
(not supported yet) */
- NPUINPUT_HOST = 3, /**< Process input frames transmitted from Host.
+ NPUINPUT_HOST = 3, /**< Process input frames transmitted from Host.
TRIA, TRIV, and TRIV2 may use this. */
- NPUINPUT_HW_RECURRING =
- 4, /**< Process input frames transmitted from third-party HW.
+ NPUINPUT_HW_RECURRING = 4, /**< Process input frames transmitted from third-party HW.
TRIV2 may use this for high-priority models. */
} npu_input_opmode;
-#define IS_DEVICE \
- (val, devname) (((val) &DEVICETYPE_MASK) == \
- DEVICETYPE_##devname) /** E.g., IS_DEVICE(dev, ASR) */
+#define IS_DEVICE \
+ (val, devname) (((val) &DEVICETYPE_MASK) == DEVICETYPE_##devname) /** E.g., IS_DEVICE(dev, ASR) */
/**
* @brief Various device types to be supported for running models
typedef enum {
PROFILE_LEVEL_EXT_META = 0, /**< Depends on extended metadata */
PROFILE_LEVEL_VISA, /**< vISA-level profiling */
- PROFILE_LEVEL_LAYER, /**< Layer-level profiling (requires the extended meta) */
+ PROFILE_LEVEL_LAYER, /**< Layer-level profiling (requires the extended meta) */
PROFILE_LEVEL_MAX
} profile_level_type;
* embedded in devices, you do not need to call register and
* register calls for ASR are ignored.
*/
-int registerNPUmodel (npudev_h dev, generic_buffer *modelfile,
- uint32_t *model_id);
+int registerNPUmodel (npudev_h dev, generic_buffer *modelfile, uint32_t *model_id);
/**
* @brief Remove the NN model from NPU
* @param[out] size tensor size
* @return 0 if no error. otherwise a negative error value
*/
-int getNPUmodel_tensorSize (npudev_h dev, uint32_t model_id, bool input,
- uint32_t index, uint32_t *size);
+int getNPUmodel_tensorSize (npudev_h dev, uint32_t model_id, bool input, uint32_t index,
+ uint32_t *size);
/**
* @brief [OPTIONAL] Set the data layout for input/output tensors
* @return @c 0 if no error. otherwise a negative error value
* @note if this function is not called, default layout/type will be used.
*/
-int setNPU_dataInfo (npudev_h dev, uint32_t model_id,
- tensors_data_info *info_in, tensors_data_info *info_out);
+int setNPU_dataInfo (npudev_h dev, uint32_t model_id, tensors_data_info *info_in,
+ tensors_data_info *info_out);
/**
* @brief [OPTIONAL] Set the inference constraint for next NPU inferences
* @return @c 0 if no error. otherwise a negative error value
* @note If this function is not called, default values are used.
*/
-int setNPU_constraint (npudev_h dev, uint32_t model_id,
- npu_constraint constraint);
+int setNPU_constraint (npudev_h dev, uint32_t model_id, npu_constraint constraint);
/**
* @brief Execute inference.
* @note This API allows for users to use pre-allocated (dmabuf) input/output buffers
* to avoid unnecessary memcpy. Make sure that they have 'BUFFER_DMABUF' types.
*/
-int runNPU_model (npudev_h dev, uint32_t model_id, npu_infer_mode mode,
- const input_buffers *input, output_buffers *output,
- npuOutputNotify cb, void *data);
+int runNPU_model (npudev_h dev, uint32_t model_id, npu_infer_mode mode, const input_buffers *input,
+ output_buffers *output, npuOutputNotify cb, void *data);
/**
* @brief Execute inference. Blocking call (wait until output is available).
* Please use runNPU_model().
* @detail There is a memcpy for the output buffer.
*/
-int runNPU_async (npudev_h dev, uint32_t model_id, const input_buffers *input,
- npuOutputNotify cb, uint64_t *sequence, void *data,
- npu_async_mode mode);
+int runNPU_async (npudev_h dev, uint32_t model_id, const input_buffers *input, npuOutputNotify cb,
+ uint64_t *sequence, void *data, npu_async_mode mode);
/**
* @brief get the current memory status for the given device
* @param[out] num_requests the number of running requests (or pending)
* @return 0 if no error, otherwise a negative errno.
*/
-int getNPU_deviceStatus (npudev_h dev, npu_status *status,
- uint32_t *num_requests);
+int getNPU_deviceStatus (npudev_h dev, npu_status *status, uint32_t *num_requests);
/**
* [IMPORTANT] Descriptions for buffer allocation APIs.
* @note This is one-shot API. Don't call multiple times for the same infernece.
* @note Internal data of npu_profile is valid until putNPU_profile is called.
*/
-int getNPU_profile_opt (npudev_h dev, int req_id, const npu_profile_opt opt,
- npu_profile *profile);
+int getNPU_profile_opt (npudev_h dev, int req_id, const npu_profile_opt opt, npu_profile *profile);
/**
* @brief [Optional] Set model data of the request to be profiled
*/
int writeNPU_log (npu_loglevel level, const char *tag, const char *format, ...);
-#define writeNPU_logInfo(tag, format, ...) \
- writeNPU_log (NPU_LOG_INFO, tag, format, ##__VA_ARGS__)
-#define writeNPU_logWarn(tag, format, ...) \
- writeNPU_log (NPU_LOG_WARN, tag, format, ##__VA_ARGS__)
-#define writeNPU_logError(tag, format, ...) \
- writeNPU_log (NPU_LOG_ERROR, tag, format, ##__VA_ARGS__)
+#define writeNPU_logInfo(tag, format, ...) writeNPU_log (NPU_LOG_INFO, tag, format, ##__VA_ARGS__)
+#define writeNPU_logWarn(tag, format, ...) writeNPU_log (NPU_LOG_WARN, tag, format, ##__VA_ARGS__)
+#define writeNPU_logError(tag, format, ...) writeNPU_log (NPU_LOG_ERROR, tag, format, ##__VA_ARGS__)
/** NPU Request/Submit Interface (decoupled version for runNPU_* APIs) */
* internally (e.g., NHWC <-> TRIV2).
* @note it's not necessary if you're going to use submitNPU_requestKernel()
*/
-int setNPU_requestData (npudev_h dev, int req_id, input_buffers *input,
- tensors_data_info *in_info, output_buffers *output,
- tensors_data_info *out_info);
+int setNPU_requestData (npudev_h dev, int req_id, input_buffers *input, tensors_data_info *in_info,
+ output_buffers *output, tensors_data_info *out_info);
/**
* @brief Set output callback of the request
* @return 0 if no error. Otherwise a negative errno
* @note it's not necessary if you're going to use submitNPU_requestKernel()
*/
-int setNPU_requestCallback (npudev_h dev, int req_id, npuOutputNotify cb,
- void *data);
+int setNPU_requestCallback (npudev_h dev, int req_id, npuOutputNotify cb, void *data);
/**
* @brief Set the request's inference mode
* @return 0 if no error. Otherwise a negative errno
* @note if this is not called, the default values are used (see typedef.h).
*/
-int setNPU_requestConstraint (npudev_h dev, int req_id,
- npu_constraint constraint);
+int setNPU_requestConstraint (npudev_h dev, int req_id, npu_constraint constraint);
/**
* @brief [OPTIONAL] Set the request's scheduler
}
void
-TensorFilterSRNPU::set_data_info (tensors_data_info *in_info,
- tensors_data_info *out_info) {
+TensorFilterSRNPU::set_data_info (tensors_data_info *in_info, tensors_data_info *out_info) {
in_info->num_info = model_meta_->input_seg_num;
for (uint32_t idx = 0; idx < in_info->num_info; ++idx) {
}
void
-TensorFilterSRNPU::feed_input_data (const GstTensorMemory *input,
- input_buffers *input_buf) {
+TensorFilterSRNPU::feed_input_data (const GstTensorMemory *input, input_buffers *input_buf) {
input_buf->num_buffers = model_meta_->input_seg_num;
for (uint32_t idx = 0; idx < input_buf->num_buffers; ++idx) {
}
void
-TensorFilterSRNPU::extract_output_data (const output_buffers *output_buf,
- GstTensorMemory *output) {
+TensorFilterSRNPU::extract_output_data (const output_buffers *output_buf, GstTensorMemory *output) {
/* internal logic error */
assert (output_buf->num_buffers == model_meta_->output_seg_num);
}
void
-TensorFilterSRNPU::invoke (const GstTensorMemory *input,
- GstTensorMemory *output) {
+TensorFilterSRNPU::invoke (const GstTensorMemory *input, GstTensorMemory *output) {
int req_id;
int status;
status = createNPU_request (dev_, model_id_, &req_id);
if (status != 0) {
- ml_loge ("Unable to create NPU request with model id (%u): %d", model_id_,
- status);
+ ml_loge ("Unable to create NPU request with model id (%u): %d", model_id_, status);
return;
}
/* feed input data to npu-engine */
feed_input_data (input, &input_buf);
- status = setNPU_requestData (dev_, req_id, &input_buf, &in_info, &output_buf,
- &out_info);
+ status = setNPU_requestData (dev_, req_id, &input_buf, &in_info, &output_buf, &out_info);
if (status != 0) {
ml_loge ("Unable to create NPU request for model %u", model_id_);
return;
}
int
-TensorFilterSRNPU::eventHandler (event_ops ops,
- GstTensorFilterFrameworkEventData &data) {
+TensorFilterSRNPU::eventHandler (event_ops ops, GstTensorFilterFrameworkEventData &data) {
return -ENOENT;
}
void
TensorFilterSRNPU::init_filter_srnpu () {
- registered =
- tensor_filter_subplugin::register_subplugin<TensorFilterSRNPU> ();
+ registered = tensor_filter_subplugin::register_subplugin<TensorFilterSRNPU> ();
}
void
void configure_instance (const GstTensorFilterProperties *prop);
void invoke (const GstTensorMemory *input, GstTensorMemory *output);
void getFrameworkInfo (GstTensorFilterFrameworkInfo &info);
- int getModelInfo (model_info_ops ops, GstTensorsInfo &in_info,
- GstTensorsInfo &out_info);
+ int getModelInfo (model_info_ops ops, GstTensorsInfo &in_info, GstTensorsInfo &out_info);
int eventHandler (event_ops ops, GstTensorFilterFrameworkEventData &data);
/* static methods */
private:
void set_data_info (tensors_data_info *in_info, tensors_data_info *out_info);
void feed_input_data (const GstTensorMemory *input, input_buffers *input_buf);
- void extract_output_data (const output_buffers *output_buf,
- GstTensorMemory *output);
+ void extract_output_data (const output_buffers *output_buf, GstTensorMemory *output);
static TensorFilterSRNPU *registered;
static const char *name;
npumgr_devices_id *devices = (npumgr_devices_id *) user_data;
NpumgrDevice *device = pdata->device;
- NPUMGR_DEVICE_GET_CLASS (device)->device_get_capabilities (
- device, &pdata->caps, &pdata->ptype);
+ NPUMGR_DEVICE_GET_CLASS (device)->device_get_capabilities (device, &pdata->caps, &pdata->ptype);
devices->types[devices->n_devices] = pdata->ptype;
devices->id[devices->n_devices] = pdata->id;
NpumgrContext *context;
G_LOCK (mutex);
- context = (NpumgrContext *) g_hash_table_lookup (ctx_table,
- GSIZE_TO_POINTER (handle));
+ context = (NpumgrContext *) g_hash_table_lookup (ctx_table, GSIZE_TO_POINTER (handle));
G_UNLOCK (mutex);
return context;
* @brief Method callback
*/
static void
-handle_method_call (GDBusConnection *connection, const gchar *sender,
- const gchar *object_path, const gchar *interface_name,
- const gchar *method_name, GVariant *parameters,
+handle_method_call (GDBusConnection *connection, const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *method_name, GVariant *parameters,
GDBusMethodInvocation *invocation, gpointer user_data) {
if (g_strcmp0 (method_name, "DeviceGetAvailableList") == 0) {
GVariantBuilder builder, builder_arr;
g_variant_builder_init (&builder_arr, G_VARIANT_TYPE ("ai"));
for (int i = 0; i < devices.n_devices; i++)
g_variant_builder_add (&builder_arr, "i", ((int *) devices.types)[i]);
- g_variant_builder_add_value (&builder,
- g_variant_builder_end (&builder_arr));
+ g_variant_builder_add_value (&builder, g_variant_builder_end (&builder_arr));
g_variant_builder_init (&builder_arr, G_VARIANT_TYPE ("au"));
for (int i = 0; i < devices.n_devices; i++)
g_variant_builder_add (&builder_arr, "u", ((int *) devices.id)[i]);
- g_variant_builder_add_value (&builder,
- g_variant_builder_end (&builder_arr));
+ g_variant_builder_add_value (&builder, g_variant_builder_end (&builder_arr));
- g_dbus_method_invocation_return_value (invocation,
- g_variant_builder_end (&builder));
+ g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
} else if (g_strcmp0 (method_name, "ContextCreate") == 0) {
int device_id = -1;
int priority = -1;
g_variant_get (parameters, "(ii)", &device_id, &priority);
if (device_id < 0 || priority < 0) {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
return;
}
- plugin_pdata *pdata =
- (plugin_pdata *) g_slist_nth_data (registered_plugins, device_id);
+ plugin_pdata *pdata = (plugin_pdata *) g_slist_nth_data (registered_plugins, device_id);
if (pdata == NULL) {
- g_dbus_method_invocation_return_error (
- invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Invalid device id");
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
+ "Invalid device id");
return;
}
npumgr_context handle;
npumgr_status_e status;
- status = NPUMGR_DEVICE_GET_CLASS (device)->context_create (
- device, device_id, priority, &handle);
+ status =
+ NPUMGR_DEVICE_GET_CLASS (device)->context_create (device, device_id, priority, &handle);
if (status == NPUMGR_STATUS_SUCCESS) {
NpumgrContext *ctx;
ctx->device = device;
if (insert_context (handle, ctx)) {
- g_dbus_method_invocation_return_value (invocation,
- g_variant_new ("(t)", handle));
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(t)", handle));
} else {
g_dbus_method_invocation_return_error (
invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
g_free (ctx);
}
} else {
- g_dbus_method_invocation_return_error (
- invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
- "Unable to add context: internal errors");
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
+ "Unable to add context: internal errors");
}
} else if (g_strcmp0 (method_name, "ContextDestroy") == 0) {
npumgr_context handle = 0;
if (remove_context (handle))
g_dbus_method_invocation_return_value (invocation, NULL);
else
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "NetworkCreate") == 0) {
GVariant *in_tensor_names_var;
GVariant *out_tensor_names_var;
- g_variant_get (parameters, "(tiatiiviiv)", &ctx_handle, &num_files,
- &input_files_iter, &in_buffer_type, &in_tensor_cnt,
- &in_tensor_names_var, &out_buffer_type, &out_tensor_cnt,
- &out_tensor_names_var);
+ g_variant_get (parameters, "(tiatiiviiv)", &ctx_handle, &num_files, &input_files_iter,
+ &in_buffer_type, &in_tensor_cnt, &in_tensor_names_var, &out_buffer_type,
+ &out_tensor_cnt, &out_tensor_names_var);
if (ctx_handle > 0 && num_files > 0 && in_tensor_cnt < NPUMGR_MAX_DIMS &&
out_tensor_cnt < NPUMGR_MAX_DIMS) {
NpumgrContext *context = find_context (ctx_handle);
if (context == NULL) {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Unable to find context");
return;
}
g_variant_iter_free (input_files_iter);
gchar **in_tensor_names = g_variant_dup_strv (in_tensor_names_var, NULL);
- gchar **out_tensor_names =
- g_variant_dup_strv (out_tensor_names_var, NULL);
+ gchar **out_tensor_names = g_variant_dup_strv (out_tensor_names_var, NULL);
npumgr_network nw_handle;
npumgr_status_e status;
status = NPUMGR_DEVICE_GET_CLASS (device)->network_create (
- device, ctx_handle, num_files, input_files_vec.data (),
- in_buffer_type, in_tensor_cnt, in_tensor_names, out_buffer_type,
- out_tensor_cnt, out_tensor_names, &nw_handle);
+ device, ctx_handle, num_files, input_files_vec.data (), in_buffer_type, in_tensor_cnt,
+ in_tensor_names, out_buffer_type, out_tensor_cnt, out_tensor_names, &nw_handle);
g_strfreev (in_tensor_names);
g_strfreev (out_tensor_names);
g_variant_unref (out_tensor_names_var);
if (status == NPUMGR_STATUS_SUCCESS) {
- g_dbus_method_invocation_return_value (
- invocation, g_variant_new ("(t)", nw_handle));
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(t)", nw_handle));
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Unable to add network");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "NetworkSetInput") == 0) {
GVariant *variant = NULL;
int index = -1;
- g_variant_get (parameters, "(ttiv)", (guint64 *) &ctx_handle,
- (guint64 *) &nw_handle, &index, &variant);
+ g_variant_get (parameters, "(ttiv)", (guint64 *) &ctx_handle, (guint64 *) &nw_handle, &index,
+ &variant);
if (ctx_handle > 0 && nw_handle > 0 && index >= 0 && variant != NULL) {
NpumgrContext *context = find_context (ctx_handle);
if (context != NULL) {
bytes = g_variant_get_data_as_bytes (variant);
if (g_bytes_get_size (bytes) != sizeof (buffer)) {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Invalid arguments detected");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments detected");
g_bytes_unref (bytes);
return;
}
memcpy (&buffer, g_bytes_get_data (bytes, NULL), sizeof (buffer));
g_bytes_unref (bytes);
- status = NPUMGR_DEVICE_GET_CLASS (device)->network_set_input (
- device, ctx_handle, nw_handle, index, &buffer);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->network_set_input (device, ctx_handle, nw_handle,
+ index, &buffer);
if (status == NPUMGR_STATUS_SUCCESS)
g_dbus_method_invocation_return_value (invocation, NULL);
else
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to set the input");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to set the input");
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "NetworkSetOutput") == 0) {
GVariant *variant = NULL;
int index = -1;
- g_variant_get (parameters, "(ttiv)", (guint64 *) &ctx_handle,
- (guint64 *) &nw_handle, &index, &variant);
+ g_variant_get (parameters, "(ttiv)", (guint64 *) &ctx_handle, (guint64 *) &nw_handle, &index,
+ &variant);
if (ctx_handle > 0 && nw_handle > 0 && index >= 0 && variant != NULL) {
NpumgrContext *context = find_context (ctx_handle);
if (context != NULL) {
bytes = g_variant_get_data_as_bytes (variant);
if (g_bytes_get_size (bytes) != sizeof (buffer)) {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Invalid arguments detected");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments detected");
g_bytes_unref (bytes);
return;
}
memcpy (&buffer, g_bytes_get_data (bytes, NULL), sizeof (buffer));
g_bytes_unref (bytes);
- status = NPUMGR_DEVICE_GET_CLASS (device)->network_set_output (
- device, ctx_handle, nw_handle, index, &buffer);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->network_set_output (device, ctx_handle,
+ nw_handle, index, &buffer);
if (status == NPUMGR_STATUS_SUCCESS)
g_dbus_method_invocation_return_value (invocation, NULL);
else
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to set the output");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to set the output");
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "NetworkPrepare") == 0) {
npumgr_context ctx_handle = 0;
npumgr_network nw_handle = 0;
- g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle,
- (guint64 *) &nw_handle);
+ g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle, (guint64 *) &nw_handle);
if (ctx_handle > 0 && nw_handle > 0) {
NpumgrContext *context = find_context (ctx_handle);
if (context != NULL) {
NpumgrDevice *device = context->device;
npumgr_status_e status;
- status = NPUMGR_DEVICE_GET_CLASS (device)->network_prepare (
- device, ctx_handle, nw_handle);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->network_prepare (device, ctx_handle, nw_handle);
if (status == NPUMGR_STATUS_SUCCESS)
g_dbus_method_invocation_return_value (invocation, NULL);
else
- g_dbus_method_invocation_return_error (
- invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to prepare network execution");
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+ G_DBUS_ERROR_UNKNOWN_OBJECT,
+ "Unable to prepare network execution");
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "NetworkDestroy") == 0) {
npumgr_context ctx_handle = 0;
npumgr_network nw_handle = 0;
- g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle,
- (guint64 *) &nw_handle);
+ g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle, (guint64 *) &nw_handle);
if (ctx_handle > 0 && nw_handle > 0) {
NpumgrContext *context = find_context (ctx_handle);
if (context != NULL) {
NpumgrDevice *device = context->device;
npumgr_status_e status;
- status = NPUMGR_DEVICE_GET_CLASS (device)->network_destroy (
- device, ctx_handle, nw_handle);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->network_destroy (device, ctx_handle, nw_handle);
if (status == NPUMGR_STATUS_SUCCESS)
g_dbus_method_invocation_return_value (invocation, NULL);
else
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the network");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the network");
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "QueryNetwork") == 0) {
npumgr_context ctx_handle = 0;
npumgr_network nw_handle = 0;
- g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle,
- (guint64 *) &nw_handle);
+ g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle, (guint64 *) &nw_handle);
if (ctx_handle > 0 && nw_handle > 0) {
NpumgrContext *context = find_context (ctx_handle);
if (context != NULL) {
npumgr_status_e status;
npumgr_query_inout_num data;
- status = NPUMGR_DEVICE_GET_CLASS (device)->query_network (
- device, ctx_handle, nw_handle, &data);
+ status =
+ NPUMGR_DEVICE_GET_CLASS (device)->query_network (device, ctx_handle, nw_handle, &data);
if (status == NPUMGR_STATUS_SUCCESS) {
g_dbus_method_invocation_return_value (
invocation, g_variant_new ("(uu)", data.n_input, data.n_output));
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the network");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the network");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "QueryInput") == 0) {
npumgr_network nw_handle = 0;
int index = -1;
- g_variant_get (parameters, "(tti)", (guint64 *) &ctx_handle,
- (guint64 *) &nw_handle, &index);
+ g_variant_get (parameters, "(tti)", (guint64 *) &ctx_handle, (guint64 *) &nw_handle, &index);
if (ctx_handle > 0 && nw_handle > 0 && index >= 0) {
NpumgrContext *context = find_context (ctx_handle);
if (context != NULL) {
npumgr_status_e status;
npumgr_query_tensor_attr data;
- status = NPUMGR_DEVICE_GET_CLASS (device)->query_input (
- device, ctx_handle, nw_handle, index, &data);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->query_input (device, ctx_handle, nw_handle,
+ index, &data);
if (status == NPUMGR_STATUS_SUCCESS) {
GBytes *bytes = g_bytes_new (&data, sizeof (data));
- GVariant *variant =
- g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
- g_dbus_method_invocation_return_value (
- invocation, g_variant_new ("(v)", variant));
+ GVariant *variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", variant));
g_bytes_unref (bytes);
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Unable to find input attr");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "QueryOutput") == 0) {
npumgr_network nw_handle = 0;
int index = -1;
- g_variant_get (parameters, "(tti)", (guint64 *) &ctx_handle,
- (guint64 *) &nw_handle, &index);
+ g_variant_get (parameters, "(tti)", (guint64 *) &ctx_handle, (guint64 *) &nw_handle, &index);
if (ctx_handle > 0 && nw_handle > 0 && index >= 0) {
NpumgrContext *context = find_context (ctx_handle);
if (context != NULL) {
npumgr_status_e status;
npumgr_query_tensor_attr data;
- status = NPUMGR_DEVICE_GET_CLASS (device)->query_output (
- device, ctx_handle, nw_handle, index, &data);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->query_output (device, ctx_handle, nw_handle,
+ index, &data);
if (status == NPUMGR_STATUS_SUCCESS) {
GBytes *bytes = g_bytes_new (&data, sizeof (data));
- GVariant *variant =
- g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
- g_dbus_method_invocation_return_value (
- invocation, g_variant_new ("(v)", variant));
+ GVariant *variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", variant));
g_bytes_unref (bytes);
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Unable to find output attr");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "BufferCreate") == 0) {
GBytes *bytes = g_variant_get_data_as_bytes (variant);
if (g_bytes_get_size (bytes) != sizeof (param)) {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Invalid arguments detected");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments detected");
g_bytes_unref (bytes);
return;
}
memcpy (¶m, g_bytes_get_data (bytes, NULL), sizeof (param));
g_bytes_unref (bytes);
- status = NPUMGR_DEVICE_GET_CLASS (device)->buffer_create (
- device, ctx_handle, ¶m, &buf);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->buffer_create (device, ctx_handle, ¶m, &buf);
if (status == NPUMGR_STATUS_SUCCESS) {
bytes = g_bytes_new (&buf, sizeof (buf));
- variant =
- g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
- g_dbus_method_invocation_return_value (
- invocation, g_variant_new ("(v)", variant));
+ variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", variant));
g_bytes_unref (bytes);
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Unable to create buffer");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "BufferMap") == 0) {
GBytes *bytes = g_variant_get_data_as_bytes (variant);
if (g_bytes_get_size (bytes) != sizeof (buf)) {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Invalid arguments detected");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments detected");
g_bytes_unref (bytes);
return;
}
g_bytes_unref (bytes);
/* TODO: how to deliver this addr to client? */
- status = NPUMGR_DEVICE_GET_CLASS (device)->buffer_map (
- device, ctx_handle, &buf, &addr);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->buffer_map (device, ctx_handle, &buf, &addr);
if (status == NPUMGR_STATUS_SUCCESS) {
GUnixFDList *fd_list = g_unix_fd_list_new ();
g_unix_fd_list_append (fd_list, buf.buf_fd, NULL);
bytes = g_bytes_new (&buf, sizeof (buf));
- variant =
- g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
+ variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
g_dbus_method_invocation_return_value_with_unix_fd_list (
invocation, g_variant_new ("(v)", variant), fd_list);
g_bytes_unref (bytes);
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Unable to map buffer");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "BufferDestroy") == 0) {
GBytes *bytes = g_variant_get_data_as_bytes (variant);
if (g_bytes_get_size (bytes) != sizeof (buf)) {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Invalid arguments detected");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments detected");
g_bytes_unref (bytes);
return;
}
memcpy (&buf, g_bytes_get_data (bytes, NULL), sizeof (buf));
g_bytes_unref (bytes);
- status = NPUMGR_DEVICE_GET_CLASS (device)->buffer_destroy (
- device, ctx_handle, &buf);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->buffer_destroy (device, ctx_handle, &buf);
if (status == NPUMGR_STATUS_SUCCESS) {
g_dbus_method_invocation_return_value (invocation, NULL);
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Unable to destroy buffer");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "ExecuteTrigger") == 0) {
npumgr_context ctx_handle = 0;
npumgr_network nw_handle = 0;
- g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle,
- (guint64 *) &nw_handle);
+ g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle, (guint64 *) &nw_handle);
if (ctx_handle > 0 && nw_handle > 0) {
NpumgrContext *context = find_context (ctx_handle);
if (context != NULL) {
NpumgrDevice *device = context->device;
npumgr_status_e status;
- status = NPUMGR_DEVICE_GET_CLASS (device)->execute_trigger (
- device, ctx_handle, nw_handle);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->execute_trigger (device, ctx_handle, nw_handle);
if (status == NPUMGR_STATUS_SUCCESS) {
g_dbus_method_invocation_return_value (invocation, NULL);
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Unable to execute network");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "ExecuteWait") == 0) {
npumgr_context ctx_handle = 0;
npumgr_network nw_handle = 0;
- g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle,
- (guint64 *) &nw_handle);
+ g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle, (guint64 *) &nw_handle);
if (ctx_handle > 0 && nw_handle > 0) {
NpumgrContext *context = find_context (ctx_handle);
if (context != NULL) {
NpumgrDevice *device = context->device;
npumgr_status_e status;
- status = NPUMGR_DEVICE_GET_CLASS (device)->execute_wait (
- device, ctx_handle, nw_handle);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->execute_wait (device, ctx_handle, nw_handle);
if (status == NPUMGR_STATUS_SUCCESS) {
g_dbus_method_invocation_return_value (invocation, NULL);
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Unable to finish execution");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
} else if (g_strcmp0 (method_name, "ExecuteRun") == 0) {
npumgr_context ctx_handle = 0;
npumgr_network nw_handle = 0;
- g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle,
- (guint64 *) &nw_handle);
+ g_variant_get (parameters, "(tt)", (guint64 *) &ctx_handle, (guint64 *) &nw_handle);
if (ctx_handle > 0 && nw_handle > 0) {
NpumgrContext *context = find_context (ctx_handle);
if (context != NULL) {
NpumgrDevice *device = context->device;
npumgr_status_e status;
- status = NPUMGR_DEVICE_GET_CLASS (device)->execute_run (
- device, ctx_handle, nw_handle);
+ status = NPUMGR_DEVICE_GET_CLASS (device)->execute_run (device, ctx_handle, nw_handle);
if (status == NPUMGR_STATUS_SUCCESS) {
g_dbus_method_invocation_return_value (invocation, NULL);
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Unable to execute network");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_OBJECT,
- "Unable to find the context");
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_OBJECT, "Unable to find the context");
}
} else {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"Invalid arguments detected");
}
}
* @brief Set property callback
*/
static GVariant *
-handle_get_property (GDBusConnection *connection, const gchar *sender,
- const gchar *object_path, const gchar *interface_name,
- const gchar *property_name, GError **error,
+handle_get_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *property_name, GError **error,
gpointer user_data) {
/* NYI */
return NULL;
* @brief Set property callback
*/
static gboolean
-handle_set_property (GDBusConnection *connection, const gchar *sender,
- const gchar *object_path, const gchar *interface_name,
- const gchar *property_name, GVariant *value,
+handle_set_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *property_name, GVariant *value,
GError **error, gpointer user_data) {
/* NYI */
return FALSE;
/**
* @brief VTable of GDBus Interface
*/
-static const GDBusInterfaceVTable interface_vtable = {
- handle_method_call, handle_get_property, handle_set_property};
+static const GDBusInterfaceVTable interface_vtable = {handle_method_call, handle_get_property,
+ handle_set_property};
/**
* @brief Callback on the bus connect has been obtained
*/
static void
-on_bus_acquired (GDBusConnection *connection, const gchar *name,
- gpointer user_data) {
+on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data) {
guint reg_id;
- reg_id = g_dbus_connection_register_object (
- connection, "/sr/odl/NPUManager/APIObject",
- introspection_data->interfaces[0], &interface_vtable, NULL, NULL, NULL);
+ reg_id = g_dbus_connection_register_object (connection, "/sr/odl/NPUManager/APIObject",
+ introspection_data->interfaces[0], &interface_vtable,
+ NULL, NULL, NULL);
if (reg_id == 0)
loge ("Failed to register object");
}
* @brief Callback on the name is acquired
*/
static void
-on_name_acquired (GDBusConnection *connection, const gchar *name,
- gpointer user_data) {}
+on_name_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data) {}
/**
* @brief Callback on the name is lost or connection has been closed
*/
static void
-on_name_lost (GDBusConnection *connection, const gchar *name,
- gpointer user_data) {
+on_name_lost (GDBusConnection *connection, const gchar *name, gpointer user_data) {
loge ("Unable to acquire name %s", name);
exit (EXIT_FAILURE);
}
init_plugins ();
- ctx_table =
- g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, ctx_destroy);
- owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM, "sr.odl.NPUManager.API",
- G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired,
- on_name_acquired, on_name_lost, NULL, NULL);
+ ctx_table = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, ctx_destroy);
+ owner_id =
+ g_bus_own_name (G_BUS_TYPE_SYSTEM, "sr.odl.NPUManager.API", G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
g_return_val_if_fail (pdev != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "DeviceGetAvailableList");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "DeviceGetAvailableList");
g_dbus_message_set_body (method_call, NULL);
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
GVariantIter *iter_id;
uint32_t idx;
- g_variant_get (g_dbus_message_get_body (method_reply), "(uaiau)",
- &pdev->n_devices, &iter_type, &iter_id);
+ g_variant_get (g_dbus_message_get_body (method_reply), "(uaiau)", &pdev->n_devices, &iter_type,
+ &iter_id);
if (pdev->n_devices > NPUMGR_MAX_DEVICES) {
g_critical ("Too many devices: %u", pdev->n_devices);
}
idx = 0;
- while (idx < NPUMGR_MAX_DEVICES &&
- g_variant_iter_loop (iter_type, "i", &pdev->types[idx++]))
+ while (idx < NPUMGR_MAX_DEVICES && g_variant_iter_loop (iter_type, "i", &pdev->types[idx++]))
;
idx = 0;
- while (idx < NPUMGR_MAX_DEVICES &&
- g_variant_iter_loop (iter_id, "u", &pdev->id[idx++]))
+ while (idx < NPUMGR_MAX_DEVICES && g_variant_iter_loop (iter_id, "u", &pdev->id[idx++]))
;
out_iter:
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "ContextCreate");
- g_dbus_message_set_body (method_call,
- g_variant_new ("(ii)", device_id, priority));
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "ContextCreate");
+ g_dbus_message_set_body (method_call, g_variant_new ("(ii)", device_id, priority));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "ContextDestroy");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "ContextDestroy");
g_dbus_message_set_body (method_call, g_variant_new ("(t)", ctx));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
* @brief This API helps in network creation.
*/
npumgr_status_e
-npumgr_network_create (npumgr_context ctx, int num_files,
- npumgr_network_defn *input_files,
+npumgr_network_create (npumgr_context ctx, int num_files, npumgr_network_defn *input_files,
npumgr_buffer_t in_buffer_type, int in_tensor_cnt,
- const char *const *in_tensor_names,
- npumgr_buffer_t out_buffer_type, int out_tensor_cnt,
- const char *const *out_tensor_names,
+ const char *const *in_tensor_names, npumgr_buffer_t out_buffer_type,
+ int out_tensor_cnt, const char *const *out_tensor_names,
npumgr_network *out_nw_handle) {
GDBusMessage *method_call;
GDBusMessage *method_reply;
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "NetworkCreate");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "NetworkCreate");
GVariantBuilder builder, builder_arr;
GUnixFDList *fd_list;
g_variant_builder_add_value (&builder, g_variant_builder_end (&builder_arr));
g_variant_builder_add (&builder, "i", in_buffer_type);
g_variant_builder_add (&builder, "i", in_tensor_cnt);
- g_variant_builder_add (&builder, "v",
- g_variant_new_strv (in_tensor_names, in_tensor_cnt));
+ g_variant_builder_add (&builder, "v", g_variant_new_strv (in_tensor_names, in_tensor_cnt));
g_variant_builder_add (&builder, "i", out_buffer_type);
g_variant_builder_add (&builder, "i", out_tensor_cnt);
- g_variant_builder_add (&builder, "v",
- g_variant_new_strv (out_tensor_names, out_tensor_cnt));
+ g_variant_builder_add (&builder, "v", g_variant_new_strv (out_tensor_names, out_tensor_cnt));
g_dbus_message_set_body (method_call, g_variant_builder_end (&builder));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
* @brief This API helps in attaching a valid input buffer to the inputs of network.
*/
npumgr_status_e
-npumgr_network_set_attribute (npumgr_context ctx, npumgr_network nw_handle,
- uint32_t wcet_ns, uint32_t deadline_ns,
- uint32_t period_ns, uint32_t yield_ns) {
+npumgr_network_set_attribute (npumgr_context ctx, npumgr_network nw_handle, uint32_t wcet_ns,
+ uint32_t deadline_ns, uint32_t period_ns, uint32_t yield_ns) {
/* NYI */
return NPUMGR_STATUS_SUCCESS;
}
* @brief This API helps in attaching a valid input buffer to the inputs of network.
*/
npumgr_status_e
-npumgr_network_set_input (npumgr_context ctx, npumgr_network nw_handle,
- int index, npumgr_buffer *input_buffer) {
+npumgr_network_set_input (npumgr_context ctx, npumgr_network nw_handle, int index,
+ npumgr_buffer *input_buffer) {
GDBusMessage *method_call;
GDBusMessage *method_reply;
npumgr_status_e status = NPUMGR_STATUS_SUCCESS;
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "NetworkSetInput");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "NetworkSetInput");
bytes = g_bytes_new (input_buffer, sizeof (*input_buffer));
variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
- g_dbus_message_set_body (
- method_call, g_variant_new ("(ttiv)", ctx, nw_handle, index, variant));
+ g_dbus_message_set_body (method_call, g_variant_new ("(ttiv)", ctx, nw_handle, index, variant));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
* @brief This API helps in attaching a valid output buffer to the outputs of network.
*/
npumgr_status_e
-npumgr_network_set_output (npumgr_context ctx, npumgr_network nw_handle,
- int index, npumgr_buffer *output_buffer) {
+npumgr_network_set_output (npumgr_context ctx, npumgr_network nw_handle, int index,
+ npumgr_buffer *output_buffer) {
GDBusMessage *method_call;
GDBusMessage *method_reply;
npumgr_status_e status = NPUMGR_STATUS_SUCCESS;
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "NetworkSetOutput");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "NetworkSetOutput");
bytes = g_bytes_new (output_buffer, sizeof (*output_buffer));
variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
- g_dbus_message_set_body (
- method_call, g_variant_new ("(ttiv)", ctx, nw_handle, index, variant));
+ g_dbus_message_set_body (method_call, g_variant_new ("(ttiv)", ctx, nw_handle, index, variant));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "NetworkPrepare");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "NetworkPrepare");
g_dbus_message_set_body (method_call, g_variant_new ("(tt)", ctx, nw_handle));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "NetworkDestroy");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "NetworkDestroy");
g_dbus_message_set_body (method_call, g_variant_new ("(tt)", ctx, nw_handle));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
* @brief This API helps in buffer creation.
*/
npumgr_status_e
-npumgr_buffer_create (npumgr_context ctx,
- npumgr_query_tensor_attr *create_param,
+npumgr_buffer_create (npumgr_context ctx, npumgr_query_tensor_attr *create_param,
npumgr_buffer *buf) {
GDBusMessage *method_call;
GDBusMessage *method_reply;
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "BufferCreate");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "BufferCreate");
bytes = g_bytes_new (create_param, sizeof (*create_param));
variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
g_dbus_message_set_body (method_call, g_variant_new ("(tv)", ctx, variant));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
g_bytes_unref (bytes);
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "BufferDestroy");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "BufferDestroy");
bytes = g_bytes_new (buf, sizeof (*buf));
variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
g_dbus_message_set_body (method_call, g_variant_new ("(tv)", ctx, variant));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
g_bytes_unref (bytes);
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
* @brief This API helps in mapping the buffer to get the CPU accessible address for read or write.
*/
npumgr_status_e
-npumgr_buffer_map (npumgr_context ctx, npumgr_buffer *buf,
- uint8_t **mapped_addr) {
+npumgr_buffer_map (npumgr_context ctx, npumgr_buffer *buf, uint8_t **mapped_addr) {
GDBusMessage *method_call;
GDBusMessage *method_reply;
npumgr_status_e status = NPUMGR_STATUS_SUCCESS;
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "BufferMap");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "BufferMap");
bytes = g_bytes_new (buf, sizeof (*buf));
variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
g_dbus_message_set_body (method_call, g_variant_new ("(tv)", ctx, variant));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
g_bytes_unref (bytes);
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
fd_list = g_dbus_message_get_unix_fd_list (method_reply);
buf->buf_fd = g_unix_fd_list_get (fd_list, 0, NULL);
- *mapped_addr =
- (uint8_t *) mmap (NULL, ALIGNED_SIZE (buf->buf_size),
- PROT_READ | PROT_WRITE, MAP_SHARED, buf->buf_fd, 0);
+ *mapped_addr = (uint8_t *) mmap (NULL, ALIGNED_SIZE (buf->buf_size), PROT_READ | PROT_WRITE,
+ MAP_SHARED, buf->buf_fd, 0);
if (*mapped_addr == MAP_FAILED)
status = NPUMGR_STATUS_ERR_FAIL;
* @brief This API helps in querying the network for no. of inputs and outputs.
*/
npumgr_status_e
-npumgr_query_network (npumgr_context ctx, npumgr_network nw_handle,
- npumgr_query_inout_num *data) {
+npumgr_query_network (npumgr_context ctx, npumgr_network nw_handle, npumgr_query_inout_num *data) {
GDBusMessage *method_call;
GDBusMessage *method_reply;
npumgr_status_e status = NPUMGR_STATUS_SUCCESS;
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "QueryNetwork");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "QueryNetwork");
g_dbus_message_set_body (method_call, g_variant_new ("(tt)", ctx, nw_handle));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
goto out;
}
- g_variant_get (g_dbus_message_get_body (method_reply), "(uu)", &data->n_input,
- &data->n_output);
+ g_variant_get (g_dbus_message_get_body (method_reply), "(uu)", &data->n_input, &data->n_output);
out:
g_object_unref (method_call);
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "QueryInput");
- g_dbus_message_set_body (method_call,
- g_variant_new ("(tti)", ctx, nw_handle, index));
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "QueryInput");
+ g_dbus_message_set_body (method_call, g_variant_new ("(tti)", ctx, nw_handle, index));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "QueryOutput");
- g_dbus_message_set_body (method_call,
- g_variant_new ("(tti)", ctx, nw_handle, index));
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "QueryOutput");
+ g_dbus_message_set_body (method_call, g_variant_new ("(tti)", ctx, nw_handle, index));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "ExecuteTrigger");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "ExecuteTrigger");
g_dbus_message_set_body (method_call, g_variant_new ("(tt)", ctx, nw_handle));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "ExecuteWait");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "ExecuteWait");
g_dbus_message_set_body (method_call, g_variant_new ("(tt)", ctx, nw_handle));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
g_return_val_if_fail (wait_until_connected (), NPUMGR_STATUS_ERR_TIMEOUT);
- method_call = g_dbus_message_new_method_call (
- _name_owner, "/sr/odl/NPUManager/APIObject", "sr.odl.NPUManager.API",
- "ExecuteRun");
+ method_call = g_dbus_message_new_method_call (_name_owner, "/sr/odl/NPUManager/APIObject",
+ "sr.odl.NPUManager.API", "ExecuteRun");
g_dbus_message_set_body (method_call, g_variant_new ("(tt)", ctx, nw_handle));
method_reply = g_dbus_connection_send_message_with_reply_sync (
- _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL,
- &error);
+ _connection, method_call, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &error);
if (method_reply == NULL) {
status = NPUMGR_STATUS_ERR_FAIL;
goto out;
}
- if (g_dbus_message_get_message_type (method_reply) ==
- G_DBUS_MESSAGE_TYPE_ERROR) {
+ if (g_dbus_message_get_message_type (method_reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_message_to_gerror (method_reply, &error);
g_critical ("error: %s\n", error->message);
g_error_free (error);
* @brief Callback on connetion success
*/
static void
-on_name_appeared (GDBusConnection *connection, const gchar *name,
- const gchar *name_owner, gpointer user_data) {
+on_name_appeared (GDBusConnection *connection, const gchar *name, const gchar *name_owner,
+ gpointer user_data) {
g_mutex_lock (&_mutex);
_connection = connection;
_name_owner = name_owner;
* @brief Callback on connetion failures
*/
static void
-on_name_vanished (GDBusConnection *connection, const gchar *name,
- gpointer user_data) {
+on_name_vanished (GDBusConnection *connection, const gchar *name, gpointer user_data) {
g_mutex_lock (&_mutex);
_thread = NULL;
g_mutex_unlock (&_mutex);
npumgr_thread (gpointer data) {
guint watcher_id;
- watcher_id = g_bus_watch_name (
- G_BUS_TYPE_SYSTEM, "sr.odl.NPUManager.API", G_BUS_NAME_WATCHER_FLAGS_NONE,
- on_name_appeared, on_name_vanished, NULL, NULL);
+ watcher_id =
+ g_bus_watch_name (G_BUS_TYPE_SYSTEM, "sr.odl.NPUManager.API", G_BUS_NAME_WATCHER_FLAGS_NONE,
+ on_name_appeared, on_name_vanished, NULL, NULL);
_loop = g_main_loop_new (NULL, FALSE);
}
static data_type
-convert_type (const npumgr_tensor_data_t &data,
- const npumgr_tensor_qnt_t &qnt) {
+convert_type (const npumgr_tensor_data_t &data, const npumgr_tensor_qnt_t &qnt) {
data_type type;
/* unknown, relying on the model */
if (lseek (model_file_.fd, 0, SEEK_SET) < 0)
return FALSE;
- if (read (model_file_.fd, (void *) meta_, NPUBIN_META_SIZE) !=
- NPUBIN_META_SIZE)
+ if (read (model_file_.fd, (void *) meta_, NPUBIN_META_SIZE) != NPUBIN_META_SIZE)
return FALSE;
if (meta_->size <= NPUBIN_META_SIZE)
/** @brief get network handle */
npumgr_network getHandle () { return handle_; }
- guint getInTensorDim (guint i, guint j) {
- return meta_->input_seg_dims[i][j];
- }
- guint getInTensorSize (guint i, npumgr_tensor_fmt_t fmt,
- npumgr_tensor_data_t type) {
+ guint getInTensorDim (guint i, guint j) { return meta_->input_seg_dims[i][j]; }
+ guint getInTensorSize (guint i, npumgr_tensor_fmt_t fmt, npumgr_tensor_data_t type) {
guint size;
if (fmt == NPUMGR_TENSOR_FMT_NHWC || fmt == NPUMGR_TENSOR_FMT_NCHW) {
int32_t getInTensorQuantZero (guint i) { return meta_->input_seg_quant_z[i]; }
float getInTensorQuantScale (guint i) { return meta_->input_seg_quant_s[i]; }
- guint getOutTensorDim (gint i, gint j) {
- return meta_->output_seg_dims[i][j];
- }
- guint getOutTensorSize (guint i, npumgr_tensor_fmt_t fmt,
- npumgr_tensor_data_t type) {
+ guint getOutTensorDim (gint i, gint j) { return meta_->output_seg_dims[i][j]; }
+ guint getOutTensorSize (guint i, npumgr_tensor_fmt_t fmt, npumgr_tensor_data_t type) {
guint size;
if (fmt == NPUMGR_TENSOR_FMT_NHWC || fmt == NPUMGR_TENSOR_FMT_NCHW) {
}
return size;
}
- int32_t getOutTensorQuantZero (gint i) {
- return meta_->output_seg_quant_z[i];
- }
+ int32_t getOutTensorQuantZero (gint i) { return meta_->output_seg_quant_z[i]; }
float getOutTensorQuantScale (gint i) { return meta_->output_seg_quant_s[i]; }
gboolean setInput (gint index, NpumgrBufferTriv2 *buffer) {
return FALSE;
in_info_.info[index].layout = convert_layout (buffer->getDataFmt ());
- in_info_.info[index].type =
- convert_type (buffer->getDataType (), buffer->getQuantType ());
+ in_info_.info[index].type = convert_type (buffer->getDataType (), buffer->getQuantType ());
- memcpy (&in_buffers_.bufs[index], buffer->getGenericBuffer (),
- sizeof (generic_buffer));
+ memcpy (&in_buffers_.bufs[index], buffer->getGenericBuffer (), sizeof (generic_buffer));
return TRUE;
}
return FALSE;
out_info_.info[index].layout = convert_layout (buffer->getDataFmt ());
- out_info_.info[index].type =
- convert_type (buffer->getDataType (), buffer->getQuantType ());
+ out_info_.info[index].type = convert_type (buffer->getDataType (), buffer->getQuantType ());
- memcpy (&out_buffers_.bufs[index], buffer->getGenericBuffer (),
- sizeof (generic_buffer));
+ memcpy (&out_buffers_.bufs[index], buffer->getGenericBuffer (), sizeof (generic_buffer));
return TRUE;
}
void setAsync (gboolean async) { async_ = async; }
gboolean isAsync () const { return async_; }
- gboolean prepare () {
- return (setNPU_dataInfo (dev_, model_id_, &in_info_, &out_info_) == 0);
- }
+ gboolean prepare () { return (setNPU_dataInfo (dev_, model_id_, &in_info_, &out_info_) == 0); }
gboolean execute () {
int req_id;
if (isAsync ()) {
async_priv_.done = FALSE;
- req_id =
- runNPU_model (dev_, model_id_, NPU_INFER_NON_BLOCKING, &in_buffers_,
- &out_buffers_, async_cb, &async_priv_);
+ req_id = runNPU_model (dev_, model_id_, NPU_INFER_NON_BLOCKING, &in_buffers_, &out_buffers_,
+ async_cb, &async_priv_);
} else {
- req_id = runNPU_model (dev_, model_id_, NPU_INFER_BLOCKING, &in_buffers_,
- &out_buffers_, NULL, NULL);
+ req_id = runNPU_model (dev_, model_id_, NPU_INFER_BLOCKING, &in_buffers_, &out_buffers_, NULL,
+ NULL);
}
return (req_id > 0);
g_mutex_lock (&async_priv_.mutex);
while (async_priv_.done != TRUE) {
- if (!g_cond_wait_until (&async_priv_.cond, &async_priv_.mutex,
- end_time)) {
+ if (!g_cond_wait_until (&async_priv_.cond, &async_priv_.mutex, end_time)) {
result = FALSE;
break;
}
*/
class NpumgrContextTriv2 {
public:
- NpumgrContextTriv2 (npudev_h dev, int priority)
- : dev_ (dev), priority_ (priority) {
+ NpumgrContextTriv2 (npudev_h dev, int priority) : dev_ (dev), priority_ (priority) {
handle_ = g_atomic_int_add (&g_ctx_handle, 1);
- nw_table_ =
- g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, nw_destroy);
- buf_table_ = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
- buf_destroy);
+ nw_table_ = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, nw_destroy);
+ buf_table_ = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, buf_destroy);
}
~NpumgrContextTriv2 () {
return g_hash_table_remove (nw_table_, GSIZE_TO_POINTER (handle));
}
NpumgrNetworkTriv2 *findNetwork (npumgr_network handle) {
- return (NpumgrNetworkTriv2 *) g_hash_table_lookup (
- nw_table_, GSIZE_TO_POINTER (handle));
+ return (NpumgrNetworkTriv2 *) g_hash_table_lookup (nw_table_, GSIZE_TO_POINTER (handle));
}
gboolean executeNetwork (npumgr_network handle, gboolean async = FALSE) {
}
NpumgrBufferTriv2 *findBuffer (npumgr_buffer_h handle) {
- return (NpumgrBufferTriv2 *) g_hash_table_lookup (
- buf_table_, GSIZE_TO_POINTER (handle));
+ return (NpumgrBufferTriv2 *) g_hash_table_lookup (buf_table_, GSIZE_TO_POINTER (handle));
}
gboolean allocBuffer (npumgr_query_tensor_attr *param, npumgr_buffer *buf) {
nbuf->setDataType (param->type);
nbuf->setQuantType (param->quant_type);
- if (!g_hash_table_insert (buf_table_, GSIZE_TO_POINTER (nbuf->getHandle ()),
- nbuf)) {
+ if (!g_hash_table_insert (buf_table_, GSIZE_TO_POINTER (nbuf->getHandle ()), nbuf)) {
cleanNPU_genericBuffer (dev_, &gbuf);
delete nbuf;
return FALSE;
};
#define NPUMGR_DEVICE(obj) &((obj)->parent)
-#define NPUMGR_DEVICE_TRIV2_GET_PRIVATE(obj) \
- ((NpumgrDeviceTriv2Private *) g_type_instance_get_private ( \
- (GTypeInstance *) obj, NPUMGR_TYPE_DEVICE_TRIV2))
+#define NPUMGR_DEVICE_TRIV2_GET_PRIVATE(obj) \
+ ((NpumgrDeviceTriv2Private *) g_type_instance_get_private ((GTypeInstance *) obj, \
+ NPUMGR_TYPE_DEVICE_TRIV2))
-G_DEFINE_TYPE_WITH_PRIVATE (NpumgrDeviceTriv2, npumgr_device_triv2,
- NPUMGR_TYPE_DEVICE);
+G_DEFINE_TYPE_WITH_PRIVATE (NpumgrDeviceTriv2, npumgr_device_triv2, NPUMGR_TYPE_DEVICE);
/* GObject */
static void triv2_finalize (GObject *object);
/* NpumgrDevice */
-static npumgr_status_e triv2_device_get_capabilities (
- NpumgrDevice *device, guint *caps, npumgr_device_type_t *ptype);
-static npumgr_status_e triv2_context_create (NpumgrDevice *device,
- int device_id, int priority,
+static npumgr_status_e triv2_device_get_capabilities (NpumgrDevice *device, guint *caps,
+ npumgr_device_type_t *ptype);
+static npumgr_status_e triv2_context_create (NpumgrDevice *device, int device_id, int priority,
npumgr_context *out_ctx);
-static npumgr_status_e triv2_context_destroy (NpumgrDevice *device,
- npumgr_context ctx);
-static npumgr_status_e triv2_network_create (
- NpumgrDevice *device, npumgr_context ctx, int num_files,
- npumgr_network_defn *input_files, npumgr_buffer_t in_buffer_type,
- int in_tensor_cnt, char **input_tensor_names,
- npumgr_buffer_t out_buffer_type, int out_tensor_cnt,
- char **output_tensor_names, npumgr_network *out_nw_handle);
-static npumgr_status_e triv2_network_set_input (NpumgrDevice *device,
- npumgr_context ctx,
- npumgr_network nw_handle,
- int index,
+static npumgr_status_e triv2_context_destroy (NpumgrDevice *device, npumgr_context ctx);
+static npumgr_status_e triv2_network_create (NpumgrDevice *device, npumgr_context ctx,
+ int num_files, npumgr_network_defn *input_files,
+ npumgr_buffer_t in_buffer_type, int in_tensor_cnt,
+ char **input_tensor_names,
+ npumgr_buffer_t out_buffer_type, int out_tensor_cnt,
+ char **output_tensor_names,
+ npumgr_network *out_nw_handle);
+static npumgr_status_e triv2_network_set_input (NpumgrDevice *device, npumgr_context ctx,
+ npumgr_network nw_handle, int index,
npumgr_buffer *input_buffer);
-static npumgr_status_e triv2_network_set_output (NpumgrDevice *device,
- npumgr_context ctx,
- npumgr_network nw_handle,
- int index,
+static npumgr_status_e triv2_network_set_output (NpumgrDevice *device, npumgr_context ctx,
+ npumgr_network nw_handle, int index,
npumgr_buffer *output_buffer);
-static npumgr_status_e triv2_network_prepare (NpumgrDevice *device,
- npumgr_context ctx,
+static npumgr_status_e triv2_network_prepare (NpumgrDevice *device, npumgr_context ctx,
npumgr_network nw_handle);
-static npumgr_status_e triv2_network_destroy (NpumgrDevice *device,
- npumgr_context ctx,
+static npumgr_status_e triv2_network_destroy (NpumgrDevice *device, npumgr_context ctx,
npumgr_network nw_handle);
-static npumgr_status_e triv2_buffer_create (
- NpumgrDevice *device, npumgr_context ctx,
- npumgr_query_tensor_attr *create_param, npumgr_buffer *buf);
-static npumgr_status_e triv2_buffer_destroy (NpumgrDevice *device,
- npumgr_context ctx,
+static npumgr_status_e triv2_buffer_create (NpumgrDevice *device, npumgr_context ctx,
+ npumgr_query_tensor_attr *create_param,
+ npumgr_buffer *buf);
+static npumgr_status_e triv2_buffer_destroy (NpumgrDevice *device, npumgr_context ctx,
npumgr_buffer *buf);
-static npumgr_status_e triv2_buffer_map (NpumgrDevice *device,
- npumgr_context ctx, npumgr_buffer *buf,
- uint8_t **mapped_addr);
-static npumgr_status_e triv2_buffer_unmap (NpumgrDevice *device,
- npumgr_context ctx,
+static npumgr_status_e triv2_buffer_map (NpumgrDevice *device, npumgr_context ctx,
+ npumgr_buffer *buf, uint8_t **mapped_addr);
+static npumgr_status_e triv2_buffer_unmap (NpumgrDevice *device, npumgr_context ctx,
npumgr_buffer *buf);
-static npumgr_status_e triv2_query_network (NpumgrDevice *device,
- npumgr_context ctx,
- npumgr_network nw_handle,
- npumgr_query_inout_num *data);
-static npumgr_status_e triv2_query_input (NpumgrDevice *device,
- npumgr_context ctx,
+static npumgr_status_e triv2_query_network (NpumgrDevice *device, npumgr_context ctx,
+ npumgr_network nw_handle, npumgr_query_inout_num *data);
+static npumgr_status_e triv2_query_input (NpumgrDevice *device, npumgr_context ctx,
npumgr_network nw_handle, int index,
npumgr_query_tensor_attr *data);
-static npumgr_status_e triv2_query_output (NpumgrDevice *device,
- npumgr_context ctx,
+static npumgr_status_e triv2_query_output (NpumgrDevice *device, npumgr_context ctx,
npumgr_network nw_handle, int index,
npumgr_query_tensor_attr *data);
-static npumgr_status_e triv2_execute_trigger (NpumgrDevice *device,
- npumgr_context ctx,
+static npumgr_status_e triv2_execute_trigger (NpumgrDevice *device, npumgr_context ctx,
npumgr_network nw_handle);
-static npumgr_status_e triv2_execute_wait (NpumgrDevice *device,
- npumgr_context ctx,
+static npumgr_status_e triv2_execute_wait (NpumgrDevice *device, npumgr_context ctx,
npumgr_network nw_handle);
-static npumgr_status_e triv2_execute_run (NpumgrDevice *device,
- npumgr_context ctx,
+static npumgr_status_e triv2_execute_run (NpumgrDevice *device, npumgr_context ctx,
npumgr_network nw_handle);
-static npumgr_status_e triv2_execute_realtime (NpumgrDevice *device,
- npumgr_context ctx,
- npumgr_network nw_handle,
- uint32_t task_handle,
+static npumgr_status_e triv2_execute_realtime (NpumgrDevice *device, npumgr_context ctx,
+ npumgr_network nw_handle, uint32_t task_handle,
uint32_t subtask_id);
-static npumgr_status_e triv2_execute_wait_realtime (NpumgrDevice *device,
- npumgr_context ctx,
- npumgr_network nw_handle,
- uint32_t *golden_val,
+static npumgr_status_e triv2_execute_wait_realtime (NpumgrDevice *device, npumgr_context ctx,
+ npumgr_network nw_handle, uint32_t *golden_val,
uint32_t **golden_addr);
-static npumgr_status_e triv2_execute_completed_realtime (
- NpumgrDevice *device, npumgr_context ctx, npumgr_network nw_handle);
+static npumgr_status_e triv2_execute_completed_realtime (NpumgrDevice *device, npumgr_context ctx,
+ npumgr_network nw_handle);
extern NpumgrDevice *
npumgr_device_triv2_new (void) {
npumgr_device_class->execute_run = triv2_execute_run;
npumgr_device_class->execute_realtime = triv2_execute_realtime;
npumgr_device_class->execute_wait_realtime = triv2_execute_wait_realtime;
- npumgr_device_class->execute_completed_realtime =
- triv2_execute_completed_realtime;
+ npumgr_device_class->execute_completed_realtime = triv2_execute_completed_realtime;
/* NYI */
}
memset (priv, '\x00', sizeof (*priv));
g_mutex_init (&priv->mutex);
- priv->ctx_table =
- g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, ctx_destroy);
+ priv->ctx_table = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, ctx_destroy);
/** TODO: How npumgr supports multiple TRIV2 devices? */
status = getNPUdeviceByTypeAny (&priv->dev, NPUCOND_TRIV2_CONN_SOCIP, 2);
/* Filling the virtual function table of TRIV2 */
static npumgr_status_e
-triv2_device_get_capabilities (NpumgrDevice *device, guint *caps,
- npumgr_device_type_t *ptype) {
+triv2_device_get_capabilities (NpumgrDevice *device, guint *caps, npumgr_device_type_t *ptype) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (caps != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ptype != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
NpumgrDeviceTriv2 *self = NPUMGR_DEVICE_TRIV2 (device);
NpumgrDeviceTriv2Private *priv = NPUMGR_DEVICE_TRIV2_GET_PRIVATE (self);
- g_return_val_if_fail (priv->dev != NULL,
- NPUMGR_STATUS_ERR_DEVICE_UNAVAILABLE);
+ g_return_val_if_fail (priv->dev != NULL, NPUMGR_STATUS_ERR_DEVICE_UNAVAILABLE);
- *caps = NPUMGR_DEVICE_CAPABILITY_MMAP |
- NPUMGR_DEVICE_CAPABILITY_MULTICONTEXT | NPUMGR_DEVICE_CAPABILITY_MMU |
- NPUMGR_DEVICE_CAPABILITY_REALTIME;
+ *caps = NPUMGR_DEVICE_CAPABILITY_MMAP | NPUMGR_DEVICE_CAPABILITY_MULTICONTEXT |
+ NPUMGR_DEVICE_CAPABILITY_MMU | NPUMGR_DEVICE_CAPABILITY_REALTIME;
*ptype = NPUMGR_DEVICE_TYPE_NPU;
return NPUMGR_STATUS_SUCCESS;
gboolean result;
g_mutex_lock (&priv->mutex);
- result =
- g_hash_table_insert (priv->ctx_table, GSIZE_TO_POINTER (handle), context);
+ result = g_hash_table_insert (priv->ctx_table, GSIZE_TO_POINTER (handle), context);
g_mutex_unlock (&priv->mutex);
return result;
NpumgrContextTriv2 *context;
g_mutex_lock (&priv->mutex);
- context = (NpumgrContextTriv2 *) g_hash_table_lookup (
- priv->ctx_table, GSIZE_TO_POINTER (handle));
+ context = (NpumgrContextTriv2 *) g_hash_table_lookup (priv->ctx_table, GSIZE_TO_POINTER (handle));
g_mutex_unlock (&priv->mutex);
return context;
NpumgrDeviceTriv2 *self = NPUMGR_DEVICE_TRIV2 (device);
NpumgrDeviceTriv2Private *priv = NPUMGR_DEVICE_TRIV2_GET_PRIVATE (self);
- g_return_val_if_fail (priv->dev != NULL,
- NPUMGR_STATUS_ERR_DEVICE_UNAVAILABLE);
+ g_return_val_if_fail (priv->dev != NULL, NPUMGR_STATUS_ERR_DEVICE_UNAVAILABLE);
NpumgrContextTriv2 *context = new NpumgrContextTriv2 (priv->dev, priority);
*ctx_handle = context->getHandle ();
static npumgr_status_e
triv2_network_create (NpumgrDevice *device, npumgr_context ctx, int num_files,
- npumgr_network_defn *input_files,
- npumgr_buffer_t in_buffer_type, int in_tensor_cnt,
- char **input_tensor_names,
- npumgr_buffer_t out_buffer_type, int out_tensor_cnt,
- char **output_tensor_names, npumgr_network *out_nw) {
+ npumgr_network_defn *input_files, npumgr_buffer_t in_buffer_type,
+ int in_tensor_cnt, char **input_tensor_names, npumgr_buffer_t out_buffer_type,
+ int out_tensor_cnt, char **output_tensor_names, npumgr_network *out_nw) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (num_files == 1, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (input_files != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (in_tensor_cnt != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
- g_return_val_if_fail (input_tensor_names != NULL,
- NPUMGR_STATUS_ERR_PARAM_INVALID);
+ g_return_val_if_fail (input_tensor_names != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (out_tensor_cnt != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
- g_return_val_if_fail (output_tensor_names != NULL,
- NPUMGR_STATUS_ERR_PARAM_INVALID);
+ g_return_val_if_fail (output_tensor_names != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (out_nw != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
NpumgrDeviceTriv2 *self = NPUMGR_DEVICE_TRIV2 (device);
g_return_val_if_fail (context != NULL, NPUMGR_STATUS_ERR_CTX_INVALID);
- NpumgrNetworkTriv2 *network =
- new NpumgrNetworkTriv2 (context->getDevice (), input_files[0]);
+ NpumgrNetworkTriv2 *network = new NpumgrNetworkTriv2 (context->getDevice (), input_files[0]);
if (!network->loadModel ())
goto err;
if (network->getInTensorCnt () != in_tensor_cnt)
}
static npumgr_status_e
-triv2_network_set_input (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle, int index,
- npumgr_buffer *buf) {
+triv2_network_set_input (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle,
+ int index, npumgr_buffer *buf) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (nw_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
NpumgrNetworkTriv2 *network = context->findNetwork (nw_handle);
g_return_val_if_fail (network != NULL, NPUMGR_STATUS_ERR_MODEL_INVALID);
- g_return_val_if_fail (network->getInTensorCnt () > index,
- NPUMGR_STATUS_ERR_PARAM_INVALID);
+ g_return_val_if_fail (network->getInTensorCnt () > index, NPUMGR_STATUS_ERR_PARAM_INVALID);
NpumgrBufferTriv2 *buffer = context->findBuffer (buf->buf_handle);
g_return_val_if_fail (buffer != NULL, NPUMGR_STATUS_ERR_FAIL);
}
static npumgr_status_e
-triv2_network_set_output (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle, int index,
- npumgr_buffer *buf) {
+triv2_network_set_output (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle,
+ int index, npumgr_buffer *buf) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (nw_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
NpumgrNetworkTriv2 *network = context->findNetwork (nw_handle);
g_return_val_if_fail (network != NULL, NPUMGR_STATUS_ERR_MODEL_INVALID);
- g_return_val_if_fail (network->getOutTensorCnt () > index,
- NPUMGR_STATUS_ERR_PARAM_INVALID);
+ g_return_val_if_fail (network->getOutTensorCnt () > index, NPUMGR_STATUS_ERR_PARAM_INVALID);
NpumgrBufferTriv2 *buffer = context->findBuffer (buf->buf_handle);
g_return_val_if_fail (buffer != NULL, NPUMGR_STATUS_ERR_FAIL);
}
static npumgr_status_e
-triv2_network_prepare (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle) {
+triv2_network_prepare (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (nw_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
}
static npumgr_status_e
-triv2_network_destroy (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle) {
+triv2_network_destroy (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (nw_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
static npumgr_status_e
triv2_buffer_create (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_query_tensor_attr *create_param,
- npumgr_buffer *buf) {
+ npumgr_query_tensor_attr *create_param, npumgr_buffer *buf) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (create_param != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
}
static npumgr_status_e
-triv2_buffer_destroy (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_buffer *buf) {
+triv2_buffer_destroy (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_buffer *buf) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (buf != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
}
static npumgr_status_e
-triv2_buffer_map (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_buffer *buf, uint8_t **mapped_addr) {
+triv2_buffer_map (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_buffer *buf,
+ uint8_t **mapped_addr) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (buf != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
}
static npumgr_status_e
-triv2_buffer_unmap (NpumgrDevice *device, npumgr_context ctx,
- npumgr_buffer *buf) {
+triv2_buffer_unmap (NpumgrDevice *device, npumgr_context ctx, npumgr_buffer *buf) {
/* NYI */
return NPUMGR_STATUS_SUCCESS;
}
static npumgr_status_e
-triv2_query_network (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle,
+triv2_query_network (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle,
npumgr_query_inout_num *inout_num) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
}
static npumgr_status_e
-triv2_query_input (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle, int index,
- npumgr_query_tensor_attr *attr) {
+triv2_query_input (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle,
+ int index, npumgr_query_tensor_attr *attr) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (nw_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
attr->n_dims = MAX_RANK;
for (guint rank = 0; rank < MAX_RANK; rank++)
attr->dims[rank] = network->getInTensorDim (index, rank);
- g_snprintf (attr->name, NPUMGR_MAX_NAME_LEN, "%s",
- network->getInTensorName (index));
+ g_snprintf (attr->name, NPUMGR_MAX_NAME_LEN, "%s", network->getInTensorName (index));
/* FIXME: their exact meaning and usage? */
for (guint rank = 0; rank < MAX_RANK; rank++) attr->strides[rank] = 1;
}
static npumgr_status_e
-triv2_query_output (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle, int index,
- npumgr_query_tensor_attr *attr) {
+triv2_query_output (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle,
+ int index, npumgr_query_tensor_attr *attr) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (nw_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
attr->n_dims = MAX_RANK;
for (guint rank = 0; rank < MAX_RANK; rank++)
attr->dims[rank] = network->getOutTensorDim (index, rank);
- g_snprintf (attr->name, NPUMGR_MAX_NAME_LEN, "%s",
- network->getOutTensorName (index));
+ g_snprintf (attr->name, NPUMGR_MAX_NAME_LEN, "%s", network->getOutTensorName (index));
/* FIXME: their exact meaning and usage? */
for (guint rank = 0; rank < MAX_RANK; rank++) attr->strides[rank] = 1;
}
static npumgr_status_e
-triv2_execute_trigger (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle) {
+triv2_execute_trigger (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (nw_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
}
static npumgr_status_e
-triv2_execute_wait (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle) {
+triv2_execute_wait (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (nw_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
}
static npumgr_status_e
-triv2_execute_run (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle) {
+triv2_execute_run (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle) {
g_return_val_if_fail (device != NULL, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (ctx_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
g_return_val_if_fail (nw_handle != 0, NPUMGR_STATUS_ERR_PARAM_INVALID);
}
static npumgr_status_e
-triv2_execute_realtime (NpumgrDevice *device, npumgr_context ctx_handle,
- npumgr_network nw_handle, uint32_t task_handle,
- uint32_t subtask_id) {
+triv2_execute_realtime (NpumgrDevice *device, npumgr_context ctx_handle, npumgr_network nw_handle,
+ uint32_t task_handle, uint32_t subtask_id) {
/* NYI */
return NPUMGR_STATUS_SUCCESS;
}
}
static npumgr_status_e
-triv2_execute_completed_realtime (NpumgrDevice *device,
- npumgr_context ctx_handle,
+triv2_execute_completed_realtime (NpumgrDevice *device, npumgr_context ctx_handle,
npumgr_network nw_handle) {
/* NYI */
return NPUMGR_STATUS_SUCCESS;
G_BEGIN_DECLS
#define NPUMGR_TYPE_DEVICE_TRIV2 (npumgr_device_triv2_get_type ())
-#define NPUMGR_DEVICE_TRIV2(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), NPUMGR_TYPE_DEVICE_TRIV2, \
- NpumgrDeviceTriv2))
+#define NPUMGR_DEVICE_TRIV2(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), NPUMGR_TYPE_DEVICE_TRIV2, NpumgrDeviceTriv2))
typedef struct _NpumgrDeviceTriv2 NpumgrDeviceTriv2;
typedef struct _NpumgrDeviceTriv2Class NpumgrDeviceTriv2Class;
/** host -> npu-engine */
virtual int extractGenericBuffer (const generic_buffer *buf, void *data,
- dataManipFunc func = nullptr,
- size_t offset = 0, size_t size = 0) = 0;
+ dataManipFunc func = nullptr, size_t offset = 0,
+ size_t size = 0) = 0;
/** npu-engine -> host */
virtual int insertGenericBuffer (void *data, generic_buffer *buf,
dataManipFunc func = nullptr) = 0;
* @param[in] size the size of generic buffer to be copied
* @return 0 if no error. otherwise a negative errno
*/
- int extractGenericBuffer (const generic_buffer *buf, void *data,
- dataManipFunc func = nullptr, size_t offset = 0,
- size_t size = 0) {
+ int extractGenericBuffer (const generic_buffer *buf, void *data, dataManipFunc func = nullptr,
+ size_t offset = 0, size_t size = 0) {
size_t count = 0;
if (buf == nullptr || data == nullptr)
* @param[in] func data manipulation function
* @return 0 if no error. otherwise a negative errno
*/
- int insertGenericBuffer (void *data, generic_buffer *buf,
- dataManipFunc func = nullptr) {
+ int insertGenericBuffer (void *data, generic_buffer *buf, dataManipFunc func = nullptr) {
if (buf == nullptr || data == nullptr)
return -EINVAL;
if (buf->size == 0)
#define TAG _N72
/** @brief constructor of buffer class */
-Buffer::Buffer (const HWmemImpl* impl)
- : HWmem (impl), num_input_ (0), num_output_ (0) {}
+Buffer::Buffer (const HWmemImpl* impl) : HWmem (impl), num_input_ (0), num_output_ (0) {}
/** @brief destructor of buffer class */
Buffer::~Buffer () {
}
}
for (uint32_t i = 0; i < meta->getOutputNum (); i++) {
- status =
- setOutputTensor (i, meta->getOutputOffset (i),
- meta->getOutputTensorSize (i, DATA_LAYOUT_SRNPU));
+ status = setOutputTensor (i, meta->getOutputOffset (i),
+ meta->getOutputTensorSize (i, DATA_LAYOUT_SRNPU));
if (status != 0) {
logerr (TAG, "failed to set output tensor: index (%d)\n", i);
return status;
if (quantizer)
quantizer->memcpy (static_cast<char *> (dst_) + dst_offset,
- static_cast<char *> (src_) + src_offset,
- slice_size);
+ static_cast<char *> (src_) + src_offset, slice_size);
else
memcpy (static_cast<char *> (dst_) + dst_offset,
static_cast<char *> (src_) + src_offset, slice_size);
}
}
}
- } else if (src_layout_ == DATA_LAYOUT_NCHW &&
- dst_layout_ == DATA_LAYOUT_TRIV2) {
+ } else if (src_layout_ == DATA_LAYOUT_NCHW && dst_layout_ == DATA_LAYOUT_TRIV2) {
/* special handling: NHWC == NCHW */
if (depth == 1)
goto try_quantize;
for (uint32_t h = 0; h < height; h++) {
for (uint32_t w = 0; w < width; w++) {
src_offset = w + width * (h + height * (d + n * depth));
- dst_offset = (d % MPA_L) +
- MPA_L * (w + width * (h + (n + d / MPA_L) * height));
+ dst_offset = (d % MPA_L) + MPA_L * (w + width * (h + (n + d / MPA_L) * height));
src_offset *= src_data_size;
dst_offset *= dst_data_size;
if (quantizer)
quantizer->memcpy (static_cast<char *> (dst_) + dst_offset,
- static_cast<char *> (src_) + src_offset,
- slice_size);
+ static_cast<char *> (src_) + src_offset, slice_size);
else
memcpy (static_cast<char *> (dst_) + dst_offset,
static_cast<char *> (src_) + src_offset, slice_size);
}
}
}
- } else if (src_layout_ == DATA_LAYOUT_TRIV2 &&
- dst_layout_ == DATA_LAYOUT_NHWC) {
+ } else if (src_layout_ == DATA_LAYOUT_TRIV2 && dst_layout_ == DATA_LAYOUT_NHWC) {
/* special handling: depth == granularity */
if (depth == granularity)
goto try_quantize;
if (quantizer)
quantizer->memcpy (static_cast<char *> (dst_) + dst_offset,
- static_cast<char *> (src_) + src_offset,
- slice_size);
+ static_cast<char *> (src_) + src_offset, slice_size);
else
memcpy (static_cast<char *> (dst_) + dst_offset,
static_cast<char *> (src_) + src_offset, slice_size);
}
}
}
- } else if (src_layout_ == DATA_LAYOUT_TRIV2 &&
- dst_layout_ == DATA_LAYOUT_NCHW) {
+ } else if (src_layout_ == DATA_LAYOUT_TRIV2 && dst_layout_ == DATA_LAYOUT_NCHW) {
/* TRIV2 --> NCHW */
slice_size = src_data_size;
for (uint32_t n = 0; n < batch; n++) {
for (uint32_t h = 0; h < height; h++) {
for (uint32_t w = 0; w < width; w++) {
dst_offset = w + width * (h + height * (d + n * depth));
- src_offset = (d % MPA_L) +
- MPA_L * (w + width * (h + (n + d / MPA_L) * height));
+ src_offset = (d % MPA_L) + MPA_L * (w + width * (h + (n + d / MPA_L) * height));
src_offset *= src_data_size;
dst_offset *= dst_data_size;
if (quantizer)
quantizer->memcpy (static_cast<char *> (dst_) + dst_offset,
- static_cast<char *> (src_) + src_offset,
- slice_size);
+ static_cast<char *> (src_) + src_offset, slice_size);
else
memcpy (static_cast<char *> (dst_) + dst_offset,
static_cast<char *> (src_) + src_offset, slice_size);
* @return 0 if no error. otherwise a negative error value
*/
int
-HostHandler::getTensorSize (uint32_t modelid, bool input, uint32_t index,
- uint32_t *size) {
+HostHandler::getTensorSize (uint32_t modelid, bool input, uint32_t index, uint32_t *size) {
Model *model = models_.find (modelid);
if (model == nullptr)
return -ENOENT;
* @return 0 if no error, otherwise a negative errno.
*/
int
-HostHandler::getProfile (int req_id, const npu_profile_opt &opt,
- npu_profile *profile) {
+HostHandler::getProfile (int req_id, const npu_profile_opt &opt, npu_profile *profile) {
if (req_id < 0 || profile == nullptr) {
logerr (TAG, "Invalid parameter provided\n");
return -EINVAL;
* @note if this function is not called, default layout/type will be used.
*/
int
-HostHandler::setDataInfo (uint32_t modelid, tensors_data_info *in,
- tensors_data_info *out) {
+HostHandler::setDataInfo (uint32_t modelid, tensors_data_info *in, tensors_data_info *out) {
Model *model = models_.find (modelid);
if (model == nullptr)
return -ENOENT;
* @return 0 if no error. Otherwise a negative errno
*/
int
-HostHandler::setRequestData (int req_id, input_buffers *input,
- tensors_data_info *in_info, output_buffers *output,
- tensors_data_info *out_info) {
+HostHandler::setRequestData (int req_id, input_buffers *input, tensors_data_info *in_info,
+ output_buffers *output, tensors_data_info *out_info) {
return device_->setRequestData (req_id, input, in_info, output, out_info);
}
* @return @c positive id if no error. otherwise a negative error value
*/
int
-HostHandler::runModel (uint32_t modelid, npu_infer_mode mode,
- const input_buffers *input, output_buffers *output,
- npuOutputNotify cb, void *data) {
+HostHandler::runModel (uint32_t modelid, npu_infer_mode mode, const input_buffers *input,
+ output_buffers *output, npuOutputNotify cb, void *data) {
Model *model = nullptr;
int req_id;
switch (mode) {
case NPU_INFER_BLOCKING: {
callbackSync sync;
- req_id =
- device_->run (NPUINPUT_HOST, model, input, output,
- callbackSync::callback, static_cast<void *> (&sync));
+ req_id = device_->run (NPUINPUT_HOST, model, input, output, callbackSync::callback,
+ static_cast<void *> (&sync));
if (req_id > 0)
sync.wait ();
} break;
/** always true cuz nothing to do */
break;
case BUFFER_MAPPED:
- return device_->deallocMemory (buffer->dmabuf, buffer->size,
- buffer->addr);
+ return device_->deallocMemory (buffer->dmabuf, buffer->size, buffer->addr);
default:
return -EINVAL;
}
* @return the segment table instance
*/
SegmentTable *
-TrinityVision2::prepareSegmentTable (const Model *model,
- const input_buffers *input,
+TrinityVision2::prepareSegmentTable (const Model *model, const input_buffers *input,
const output_buffers *output) {
const Metadata *meta = model->getMetadata ();
- if (meta == nullptr ||
- (input != nullptr && meta->getInputNum () != input->num_buffers)) {
+ if (meta == nullptr || (input != nullptr && meta->getInputNum () != input->num_buffers)) {
logerr (TAG, "Invalid metadata info provided\n");
return nullptr;
}
}
if (npu_dspm_size < model_dspm_size) {
- logerr (TAG, "The minimum DSPM size of model is %u KiB (NPU: %u KiB)\n",
- model_dspm_size / 1024, npu_dspm_size / 1024);
+ logerr (TAG, "The minimum DSPM size of model is %u KiB (NPU: %u KiB)\n", model_dspm_size / 1024,
+ npu_dspm_size / 1024);
return -ENOMEM;
}
goto delete_exit;
}
- status = comm_.extractGenericBuffer (model_buf, model->getData (),
- nullptr, 0, NPUBIN_META_SIZE);
+ status =
+ comm_.extractGenericBuffer (model_buf, model->getData (), nullptr, 0, NPUBIN_META_SIZE);
if (status != 0) {
logerr (TAG, "Failed to extract generic buffer: %d\n", status);
goto delete_exit;
goto delete_exit;
}
- status =
- comm_.extractGenericBuffer (model_buf, hwmem_prog->getData (), nullptr,
- model->getMetadata ()->getMetaSize (),
- model->getMetadata ()->getProgramSize ());
+ status = comm_.extractGenericBuffer (model_buf, hwmem_prog->getData (), nullptr,
+ model->getMetadata ()->getMetaSize (),
+ model->getMetadata ()->getProgramSize ());
if (status != 0) {
logerr (TAG, "Failed to extract generic buffer: %d\n", status);
goto delete_exit;
config.metadata_ext_dbuf_fd = hwmem_extended->getDmabuf ();
config.metadata_ext_size = extended_size;
- status =
- comm_.extractGenericBuffer (model_buf, hwmem_extended->getData (),
- nullptr, NPUBIN_META_SIZE, extended_size);
+ status = comm_.extractGenericBuffer (model_buf, hwmem_extended->getData (), nullptr,
+ NPUBIN_META_SIZE, extended_size);
if (status != 0) {
logerr (TAG, "Failed to extract generic buffer: %d\n", status);
goto delete_exit;
config.num_visa_insts = model->getNumInsts ();
- status =
- api_->registerModel (&config, model->getMetadata ()->getNPUVersion ());
+ status = api_->registerModel (&config, model->getMetadata ()->getNPUVersion ());
if (status != 0)
goto delete_exit;
status = comm_.extractGenericBuffer (
model_buf, hwmem_weight->getData (), nullptr,
- model->getMetadata ()->getMetaSize () +
- model->getMetadata ()->getProgramSize (),
+ model->getMetadata ()->getMetaSize () + model->getMetadata ()->getProgramSize (),
model->getMetadata ()->getWeightSize ());
if (status != 0) {
logerr (TAG, "Failed to extract generic buffer: %d\n", status);
* @return 0 if no error. otherwise a negative error value
*/
int
-TrinityVision2::getTensorSize (const Model *model, bool input, uint32_t index,
- uint32_t *size) {
+TrinityVision2::getTensorSize (const Model *model, bool input, uint32_t index, uint32_t *size) {
const Metadata *meta = model->getMetadata ();
if (meta == nullptr)
return -EINVAL;
if (input)
- *size =
- meta->getInputTensorSize (index, meta->getInputSegmentLayout (index));
+ *size = meta->getInputTensorSize (index, meta->getInputSegmentLayout (index));
else
- *size =
- meta->getOutputTensorSize (index, meta->getOutputSegmentLayout (index));
+ *size = meta->getOutputTensorSize (index, meta->getOutputSegmentLayout (index));
return 0;
}
/** @brief implementation of TRIV2's run() */
int
-TrinityVision2::run (npu_input_opmode opmode, const Model *model,
- const input_buffers *input, output_buffers *output,
- npuOutputNotify cb, void *cb_data) {
+TrinityVision2::run (npu_input_opmode opmode, const Model *model, const input_buffers *input,
+ output_buffers *output, npuOutputNotify cb, void *cb_data) {
if (!initialized ()) {
logerr (TAG, "Uninitialized device; should use libnpuhost APIs\n");
return -EPERM;
if (!segt->getInputSegment (idx)->isExternal ()) {
uint32_t seg_offset = segt->getInputSegmentOffset (idx);
auto func = std::bind (TrinityVision2::manipulateData, model, idx, true,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3);
+ std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
status = comm_.extractGenericBuffer (
- &input->bufs[idx],
- segt->getInputSegment (idx)->getData () + seg_offset, func);
+ &input->bufs[idx], segt->getInputSegment (idx)->getData () + seg_offset, func);
if (status != 0) {
logerr (TAG, "Failed to feed input segment: %d\n", status);
return status;
req->setModel (model);
req->setInferData (segt);
req->setOutputBuffers (output);
- req->setCallback (
- std::bind (&TrinityVision2::callback, this, req, cb, cb_data));
+ req->setCallback (std::bind (&TrinityVision2::callback, this, req, cb, cb_data));
int req_id = req->getID ();
status = scheduler_->submitRequest (req);
if (output->bufs[idx].type == BUFFER_DMABUF) {
/* it's external memory. can't do */
continue;
- } else if (output->bufs[idx].addr == nullptr ||
- output->bufs[idx].size == 0) {
+ } else if (output->bufs[idx].addr == nullptr || output->bufs[idx].size == 0) {
output->bufs[idx].type = BUFFER_MAPPED;
output->bufs[idx].size = output_tensor_size;
/** user needs to free this */
}
}
- auto func = std::bind (TrinityVision2::manipulateData, model, idx, false,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3);
+ auto func = std::bind (TrinityVision2::manipulateData, model, idx, false, std::placeholders::_1,
+ std::placeholders::_2, std::placeholders::_3);
void *dst;
#ifdef __FPGA__
/* this is fpga workaround codes for syncing output data */
logerr (TAG, "Unable to allocate FPGA temp buffer\n");
break;
}
- api_->fpga_memcpy (output_segment->getDmabuf (),
- segt->getOutputSegmentOffset (idx), dst,
+ api_->fpga_memcpy (output_segment->getDmabuf (), segt->getOutputSegmentOffset (idx), dst,
output_segment->getSize ());
#else
dst = output_segment->getData () + segt->getOutputSegmentOffset (idx);
}
int
-TrinityVision2::setRequestData (int req_id, input_buffers *input,
- tensors_data_info *in_info,
- output_buffers *output,
- tensors_data_info *out_info) {
+TrinityVision2::setRequestData (int req_id, input_buffers *input, tensors_data_info *in_info,
+ output_buffers *output, tensors_data_info *out_info) {
Request *req = scheduler_->findRequest (req_id);
if (req == nullptr) {
logerr (TAG, "Unable to find the request with ID (%d)\n", req_id);
if (!segt->getInputSegment (idx)->isExternal ()) {
uint32_t seg_offset = segt->getInputSegmentOffset (idx);
auto func = std::bind (TrinityVision2::manipulateData, model, idx, true,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3);
+ std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
int status = comm_.extractGenericBuffer (
- &input->bufs[idx],
- segt->getInputSegment (idx)->getData () + seg_offset, func);
+ &input->bufs[idx], segt->getInputSegment (idx)->getData () + seg_offset, func);
if (status != 0) {
logerr (TAG, "Failed to feed input segment: %d\n", status);
return status;
}
int
-TrinityVision2::setRequestCallback (int req_id, npuOutputNotify cb,
- void *data) {
+TrinityVision2::setRequestCallback (int req_id, npuOutputNotify cb, void *data) {
Request *req = scheduler_->findRequest (req_id);
if (req == nullptr) {
logerr (TAG, "Unable to find the request with ID (%d)\n", req_id);
case NPU_INFER_NON_BLOCKING:
if (req->getCallback () == nullptr) {
logwarn (TAG, "inferencing without output callback...\n");
- req->setCallback (
- std::bind (&TrinityVision2::callback, this, req, nullptr, nullptr));
+ req->setCallback (std::bind (&TrinityVision2::callback, this, req, nullptr, nullptr));
}
status = scheduler_->submitRequest (req);
break;
* Addr(x,y,z) = Addr(0,0,0) + (z % 64) + (64 * x) + ymod * y + zmod * (z / 64)
*/
size_t
-TrinityVision2::manipulateData (const Model *model, uint32_t idx, bool is_input,
- void *dst, void *src, size_t size) {
+TrinityVision2::manipulateData (const Model *model, uint32_t idx, bool is_input, void *dst,
+ void *src, size_t size) {
const Metadata *meta = model->getMetadata ();
DataConverter converter (is_input);
#else
size_t
-TrinityVision2::manipulateData (const Model *model, uint32_t idx, bool is_input,
- void *dst, void *src, size_t size) {
+TrinityVision2::manipulateData (const Model *model, uint32_t idx, bool is_input, void *dst,
+ void *src, size_t size) {
memcpy (dst, src, size);
return size;
}
int unregisterModel (uint32_t modelid);
int unregisterModels ();
- int getTensorSize (uint32_t modelid, bool input, uint32_t index,
- uint32_t *size);
+ int getTensorSize (uint32_t modelid, bool input, uint32_t index, uint32_t *size);
int getProfile (int req_id, const npu_profile_opt &opt, npu_profile *profile);
int setProfileModel (int req_id, uint32_t model_id);
int getTops (uint32_t *tops);
int getDspmSize (uint32_t *dspm);
- int setDataInfo (uint32_t modelid, tensors_data_info *in,
- tensors_data_info *out);
+ int setDataInfo (uint32_t modelid, tensors_data_info *in, tensors_data_info *out);
int setConstraint (uint32_t modelid, npuConstraint constraint);
Model *getModel (uint32_t modelid);
int deallocGenericBuffer (generic_buffer *buffer);
int deallocGenericBuffer (generic_buffers *buffers);
- int runModel (uint32_t modelid, npu_infer_mode mode,
- const input_buffers *input, output_buffers *output = nullptr,
- npuOutputNotify cb = nullptr, void *data = nullptr);
+ int runModel (uint32_t modelid, npu_infer_mode mode, const input_buffers *input,
+ output_buffers *output = nullptr, npuOutputNotify cb = nullptr,
+ void *data = nullptr);
int createRequest (uint32_t model_id, int *req_id);
int removeRequest (int req_id);
int getRequestModel (int req_id, uint32_t *model_id);
- int setRequestData (int req_id, input_buffers *input,
- tensors_data_info *in_info, output_buffers *output,
- tensors_data_info *out_info);
+ int setRequestData (int req_id, input_buffers *input, tensors_data_info *in_info,
+ output_buffers *output, tensors_data_info *out_info);
int setRequestCallback (int req_id, npuOutputNotify cb, void *data);
int setRequestMode (int req_id, npu_infer_mode mode);
int setRequestConstraint (int req_id, npu_constraint constraint);
- int setRequestScheduler (int req_id, npu_scheduler sched,
- npu_scheduler_param sched_param);
+ int setRequestScheduler (int req_id, npu_scheduler sched, npu_scheduler_param sched_param);
int submitRequest (int req_id);
int submitRequestKernel (int req_id);
int deallocMemory (int dmabuf_fd, size_t size, void *addr);
/** virtual methods to implement each device's behaviors */
- virtual int setModel (const generic_buffer *model, Model **model_ptr) {
- return -EPERM;
- }
+ virtual int setModel (const generic_buffer *model, Model **model_ptr) { return -EPERM; }
virtual int unsetModel (Model *model) { return -EPERM; }
- virtual int getTensorSize (const Model *model, bool input, uint32_t index,
- uint32_t *size) {
+ virtual int getTensorSize (const Model *model, bool input, uint32_t index, uint32_t *size) {
return -EPERM;
}
- virtual int run (npu_input_opmode opmode, const Model *model,
- const input_buffers *input, output_buffers *output = nullptr,
- npuOutputNotify cb = nullptr, void *cb_data = nullptr) = 0;
+ virtual int run (npu_input_opmode opmode, const Model *model, const input_buffers *input,
+ output_buffers *output = nullptr, npuOutputNotify cb = nullptr,
+ void *cb_data = nullptr) = 0;
virtual int createRequest (const Model *model, int *req_id) = 0;
virtual int removeRequest (int req_id) = 0;
virtual int getRequestModel (int req_id, uint32_t *model_id) = 0;
- virtual int setRequestData (int req_id, input_buffers *input,
- tensors_data_info *in_info,
- output_buffers *output,
- tensors_data_info *out_info) = 0;
- virtual int setRequestCallback (int req_id, npuOutputNotify cb,
- void *data) = 0;
+ virtual int setRequestData (int req_id, input_buffers *input, tensors_data_info *in_info,
+ output_buffers *output, tensors_data_info *out_info) = 0;
+ virtual int setRequestCallback (int req_id, npuOutputNotify cb, void *data) = 0;
virtual int setRequestMode (int req_id, npu_infer_mode mode) = 0;
virtual int setRequestConstraint (int req_id, npu_constraint constraint) = 0;
- virtual int setRequestScheduler (int req_id, npu_scheduler sched,
- npu_scheduler_param param) = 0;
+ virtual int setRequestScheduler (int req_id, npu_scheduler sched, npu_scheduler_param param) = 0;
virtual int submitRequest (int req_id) = 0;
virtual int submitRequestKernel (int req_id) = 0;
TrinityVision2 (int id) : Device (NPUCOND_TRIV2_CONN_SOCIP, id) {}
~TrinityVision2 () {}
- static size_t manipulateData (const Model *model, uint32_t idx, bool is_input,
- void *dst, void *src, size_t size);
+ static size_t manipulateData (const Model *model, uint32_t idx, bool is_input, void *dst,
+ void *src, size_t size);
- SegmentTable *prepareSegmentTable (const Model *model,
- const input_buffers *input,
+ SegmentTable *prepareSegmentTable (const Model *model, const input_buffers *input,
const output_buffers *output = nullptr);
int setModel (const generic_buffer *model, Model **model_ptr);
int unsetModel (Model *model);
- int getTensorSize (const Model *model, bool input, uint32_t index,
- uint32_t *size);
+ int getTensorSize (const Model *model, bool input, uint32_t index, uint32_t *size);
int checkDspmSize (const Model *model);
- int run (npu_input_opmode opmode, const Model *model,
- const input_buffers *input, output_buffers *output = nullptr,
- npuOutputNotify cb = nullptr, void *cb_data = nullptr);
+ int run (npu_input_opmode opmode, const Model *model, const input_buffers *input,
+ output_buffers *output = nullptr, npuOutputNotify cb = nullptr, void *cb_data = nullptr);
int createRequest (const Model *model, int *req_id);
int removeRequest (int req_id);
int getRequestModel (int req_id, uint32_t *model_id);
- int setRequestData (int req_id, input_buffers *input,
- tensors_data_info *in_info, output_buffers *output,
- tensors_data_info *out_info);
+ int setRequestData (int req_id, input_buffers *input, tensors_data_info *in_info,
+ output_buffers *output, tensors_data_info *out_info);
int setRequestCallback (int req_id, npuOutputNotify cb, void *data);
int setRequestMode (int req_id, npu_infer_mode mode);
int setRequestConstraint (int req_id, npu_constraint constraint);
- int setRequestScheduler (int req_id, npu_scheduler sched,
- npu_scheduler_param sched_param);
+ int setRequestScheduler (int req_id, npu_scheduler sched, npu_scheduler_param sched_param);
int submitRequest (int req_id);
int submitRequestKernel (int req_id);
* @return 0 if no error, otherwise a negative errno
*/
int
-HostInputService::submit (const DriverAPI *api, const Request *req,
- outputCallback callback) {
+HostInputService::submit (const DriverAPI *api, const Request *req, outputCallback callback) {
if (api == nullptr || req == nullptr) {
logerr (TAG, "Invalid arguments\n");
return -EINVAL;
return -EINVAL;
}
- taskFunc func =
- std::bind (&HostInputService::invoke, this, api, req, callback);
+ taskFunc func = std::bind (&HostInputService::invoke, this, api, req, callback);
ThreadTask *task = new ThreadTask (req->getID (), func);
return ThreadPool::getInstance ().enqueueTask (task);
}
/** FIXME: update input_config fields */
if (req->getScheduler () == NPU_SCHEDULER_VD) {
if (req->getSchedulerParam ()) {
- memcpy (&input_config.task_handle, req->getSchedulerParam (),
- sizeof (uint32_t) * 2);
+ memcpy (&input_config.task_handle, req->getSchedulerParam (), sizeof (uint32_t) * 2);
} else {
input_config.task_handle = 0;
input_config.subtask_idx = 0;
* @return 0 if no error, otherwise a negative errno
*/
int
-HostInputService::invoke (const DriverAPI *api, const Request *req,
- outputCallback callback) {
+HostInputService::invoke (const DriverAPI *api, const Request *req, outputCallback callback) {
device_state_t state;
const Model *model;
HWmem *data;
* @return 0 if no error, otherwise a negativ errno
*/
int
-HwInputService::submit (const DriverAPI *api, const Request *req,
- outputCallback callback) {
+HwInputService::submit (const DriverAPI *api, const Request *req, outputCallback callback) {
if (api == nullptr || req == nullptr) {
logerr (TAG, "Invalid arguments\n");
return -EINVAL;
/** FIXME: update input_config fields */
if (req->getScheduler () == NPU_SCHEDULER_VD) {
if (req->getSchedulerParam ()) {
- memcpy (&input_config.task_handle, req->getSchedulerParam (),
- sizeof (uint32_t) * 2);
+ memcpy (&input_config.task_handle, req->getSchedulerParam (), sizeof (uint32_t) * 2);
} else {
input_config.task_id = req->getID ();
}
* @return req_id if no error, otherwise a negative errno
*/
int
-HwInputService::invoke (const DriverAPI *api, const Request *req,
- outputCallback callback) {
+HwInputService::invoke (const DriverAPI *api, const Request *req, outputCallback callback) {
device_state_t state;
const Model *model;
HWmem *data;
return;
if (hwmem->getBaseAddr () != nullptr) {
- hwmem->getDriverAPI ()->munmap (hwmem->getBaseAddr (),
- ALIGNED_SIZE (hwmem->getSize ()));
+ hwmem->getDriverAPI ()->munmap (hwmem->getBaseAddr (), ALIGNED_SIZE (hwmem->getSize ()));
hwmem->setBaseAddr (nullptr);
}
if (hwmem->getDmabuf () >= 0) {
- hwmem->getDriverAPI ()->dealloc (hwmem->getDmabuf (),
- hwmem->isContiguous ());
+ hwmem->getDriverAPI ()->dealloc (hwmem->getDmabuf (), hwmem->isContiguous ());
hwmem->setDmabuf (-1);
hwmem->setSize (0);
return -EBUSY;
}
- int dmabuf = hwmem->getDriverAPI ()->alloc (ALIGNED_SIZE (size),
- hwmem->isContiguous ());
+ int dmabuf = hwmem->getDriverAPI ()->alloc (ALIGNED_SIZE (size), hwmem->isContiguous ());
if (dmabuf < 0)
return dmabuf;
size_t getOffset () const { return offset_; }
void *getBaseAddr () const { return base_addr_; }
HWmem *getParent () const { return parent_; }
- bool isExternal () const {
- return nullptr != dynamic_cast<const HWmemExternal *> (impl_);
- }
+ bool isExternal () const { return nullptr != dynamic_cast<const HWmemExternal *> (impl_); }
bool isContiguous () const { return contiguous_; }
/** set private member variables */
const HWmemImpl *impl_; /**< HWmem impl. */
const DriverAPI *api_; /**< driver API */
- int dmabuf_; /**< dmabuf fd of hwmem (equal to base address when mapped) */
+ int dmabuf_; /**< dmabuf fd of hwmem (equal to base address when mapped) */
void *base_addr_; /**< base address of hwmem */
size_t offset_; /**< offset of hwmem (starting from base address) */
size_t size_; /**< size of hwmem */
public:
static HostInputService &getInstance ();
- int submit (const DriverAPI *api, const Request *request,
- outputCallback callback = nullptr);
+ int submit (const DriverAPI *api, const Request *request, outputCallback callback = nullptr);
int remove (const DriverAPI *api, int request_id);
private:
/** do not allow to directly call invoke () */
- int invoke (const DriverAPI *api, const Request *request,
- outputCallback callback = nullptr);
+ int invoke (const DriverAPI *api, const Request *request, outputCallback callback = nullptr);
/** singleton pattern */
static std::unique_ptr<HostInputService> instance_;
static std::once_flag once_flag_;
public:
static HwInputService &getInstance ();
- int submit (const DriverAPI *api, const Request *request,
- outputCallback callback = nullptr);
+ int submit (const DriverAPI *api, const Request *request, outputCallback callback = nullptr);
int remove (const DriverAPI *api, int request_id);
private:
- int invoke (const DriverAPI *api, const Request *request,
- outputCallback callback = nullptr);
+ int invoke (const DriverAPI *api, const Request *request, outputCallback callback = nullptr);
/** singleton pattern */
static std::unique_ptr<HwInputService> instance_;
static std::once_flag once_flag_;
* Below allocates the actual memory. So, the caller don't need to call alloc().
*/
virtual int allocMemory (size_t size, void **addr) { return -EINVAL; }
- virtual int deallocMemory (int dmabuf, size_t size, void *addr) {
- return -EINVAL;
- }
+ virtual int deallocMemory (int dmabuf, size_t size, void *addr) { return -EINVAL; }
/**
* Below does not allocate actual memory as we don't know the type of generic buffer
virtual SegmentTable *allocSegmentTable (HWmemImpl *impl) { return nullptr; }
protected:
- const DriverAPI
- *api_; /**< driver API that this allocator is supposed to access */
+ const DriverAPI *api_; /**< driver API that this allocator is supposed to access */
};
#endif /* __NPU_ENGINE_MEM_H__ */
Metadata_v1::createInstance (npubin_meta *meta) {
Metadata_v1 *metadata = new Metadata_v1 (meta);
- if (metadata->getSize () != metadata->getMetaSize () +
- metadata->getProgramSize () +
- metadata->getWeightSize ())
+ if (metadata->getSize () !=
+ metadata->getMetaSize () + metadata->getProgramSize () + metadata->getWeightSize ())
goto sanity_violation;
return metadata;
goto sanity_violation;
if (metadata->getOutputNum () > MAX_TENSORS)
goto sanity_violation;
- if (metadata->getSize () != metadata->getMetaSize () +
- metadata->getProgramSize () +
- metadata->getWeightSize ())
+ if (metadata->getSize () !=
+ metadata->getMetaSize () + metadata->getProgramSize () + metadata->getWeightSize ())
goto sanity_violation;
return metadata;
uint32_t elem_size = getInputElemSize (idx);
uint32_t tensor_size = elem_size;
- for (uint32_t rank_idx = 0; rank_idx < MAX_RANK; rank_idx++)
- tensor_size *= dims[rank_idx];
+ for (uint32_t rank_idx = 0; rank_idx < MAX_RANK; rank_idx++) tensor_size *= dims[rank_idx];
uint32_t granularity = DATA_GRANULARITY;
uint32_t shift = DATA_GRANULARITY_SHIFT;
granularity /= div;
/** special handling for TRIV */
- if (layout == DATA_LAYOUT_SRNPU && dims[3] != 3 &&
- dims[3] % granularity != 0) {
+ if (layout == DATA_LAYOUT_SRNPU && dims[3] != 3 && dims[3] % granularity != 0) {
uint32_t depth;
depth = (dims[3] + granularity - 1) >> shift;
uint32_t elem_size = getOutputElemSize (idx);
uint32_t tensor_size = elem_size;
- for (uint32_t rank_idx = 0; rank_idx < MAX_RANK; rank_idx++)
- tensor_size *= dims[rank_idx];
+ for (uint32_t rank_idx = 0; rank_idx < MAX_RANK; rank_idx++) tensor_size *= dims[rank_idx];
uint32_t granularity = DATA_GRANULARITY;
uint32_t shift = DATA_GRANULARITY_SHIFT;
granularity /= div;
/** special handling for TRIV */
- if (layout == DATA_LAYOUT_SRNPU && dims[3] != 3 &&
- dims[3] % granularity != 0) {
+ if (layout == DATA_LAYOUT_SRNPU && dims[3] != 3 && dims[3] % granularity != 0) {
uint32_t depth;
depth = (dims[3] + granularity - 1) >> shift;
goto sanity_violation;
}
- if (metadata->getSize () != metadata->getMetaSize () +
- metadata->getProgramSize () +
- metadata->getWeightSize ())
+ if (metadata->getSize () !=
+ metadata->getMetaSize () + metadata->getProgramSize () + metadata->getWeightSize ())
goto sanity_violation;
return metadata;
uint32_t elem_size = getInputElemSize (idx);
uint32_t tensor_size = elem_size;
- for (uint32_t rank_idx = 0; rank_idx < MAX_RANK; rank_idx++)
- tensor_size *= dims[rank_idx];
+ for (uint32_t rank_idx = 0; rank_idx < MAX_RANK; rank_idx++) tensor_size *= dims[rank_idx];
if (layout == DATA_LAYOUT_NONE || layout == DATA_LAYOUT_TRIV2) {
uint32_t granularity = DATA_GRANULARITY;
uint32_t elem_size = getOutputElemSize (idx);
uint32_t tensor_size = elem_size;
- for (uint32_t rank_idx = 0; rank_idx < MAX_RANK; rank_idx++)
- tensor_size *= dims[rank_idx];
+ for (uint32_t rank_idx = 0; rank_idx < MAX_RANK; rank_idx++) tensor_size *= dims[rank_idx];
if (layout == DATA_LAYOUT_NONE || layout == DATA_LAYOUT_TRIV2) {
uint32_t granularity = DATA_GRANULARITY;
for (uint32_t idx = 0; idx < in->num_info; idx++) {
if (meta_->getInputSegmentLayout (idx) == DATA_LAYOUT_RAW &&
- in->info[idx].layout != DATA_LAYOUT_MODEL &&
- in->info[idx].layout != DATA_LAYOUT_NHWC &&
+ in->info[idx].layout != DATA_LAYOUT_MODEL && in->info[idx].layout != DATA_LAYOUT_NHWC &&
in->info[idx].layout != DATA_LAYOUT_NCHW)
logwarn (TAG, "input[%u] is raw data. skip layout conversion\n", idx);
}
for (uint32_t idx = 0; idx < out->num_info; idx++) {
if (meta_->getOutputSegmentLayout (idx) == DATA_LAYOUT_RAW &&
- out->info[idx].layout != DATA_LAYOUT_MODEL &&
- out->info[idx].layout != DATA_LAYOUT_NHWC &&
+ out->info[idx].layout != DATA_LAYOUT_MODEL && out->info[idx].layout != DATA_LAYOUT_NHWC &&
out->info[idx].layout != DATA_LAYOUT_NCHW)
logwarn (TAG, "output[%u] is raw data. skip layout conversion\n", idx);
}
}
if (in_.num_info <= idx) {
- logerr (
- TAG,
- "Input tensor info mismatch. Do setNPU_dataInfo() first properly\n");
+ logerr (TAG, "Input tensor info mismatch. Do setNPU_dataInfo() first properly\n");
return 0;
}
}
if (out_.num_info <= idx) {
- logerr (
- TAG,
- "Output tensor info mismatch. Do setNPU_dataInfo() first properly\n");
+ logerr (TAG, "Output tensor info mismatch. Do setNPU_dataInfo() first properly\n");
return 0;
}
}
if (in_.num_info <= idx) {
- logerr (
- TAG,
- "Input tensor info mismatch. Do setNPU_dataInfo() first properly\n");
+ logerr (TAG, "Input tensor info mismatch. Do setNPU_dataInfo() first properly\n");
return nullptr;
}
}
if (out_.num_info <= idx) {
- logerr (
- TAG,
- "Output tensor info mismatch. Do setNPU_dataInfo() first properly\n");
+ logerr (TAG, "Output tensor info mismatch. Do setNPU_dataInfo() first properly\n");
return nullptr;
}
virtual uint32_t getInputOffset (uint32_t idx) const = 0;
virtual uint32_t getOutputOffset (uint32_t idx) const = 0;
- virtual uint32_t getInputTensorSize (uint32_t idx,
- data_layout layout) const = 0;
- virtual uint32_t getOutputTensorSize (uint32_t idx,
- data_layout layout) const = 0;
+ virtual uint32_t getInputTensorSize (uint32_t idx, data_layout layout) const = 0;
+ virtual uint32_t getOutputTensorSize (uint32_t idx, data_layout layout) const = 0;
virtual uint32_t getInputElemSize (uint32_t idx) const = 0;
virtual uint32_t getOutputElemSize (uint32_t idx) const = 0;
virtual const uint32_t *getInputDims (uint32_t idx) const = 0;
virtual const uint32_t *getOutputDims (uint32_t idx) const = 0;
- virtual uint32_t getInputQuantZero (uint32_t idx) const {
- return default_quant_zero;
- }
- virtual float getInputQuantScale (uint32_t idx) const {
- return default_quant_scale;
- }
+ virtual uint32_t getInputQuantZero (uint32_t idx) const { return default_quant_zero; }
+ virtual float getInputQuantScale (uint32_t idx) const { return default_quant_scale; }
- virtual uint32_t getOutputQuantZero (uint32_t idx) const {
- return default_quant_zero;
- }
- virtual float getOutputQuantScale (uint32_t idx) const {
- return default_quant_scale;
- }
+ virtual uint32_t getOutputQuantZero (uint32_t idx) const { return default_quant_zero; }
+ virtual float getOutputQuantScale (uint32_t idx) const { return default_quant_scale; }
- virtual data_type getInputQuantType (uint32_t idx) const {
- return default_data_type;
- }
- virtual data_type getOutputQuantType (uint32_t idx) const {
- return default_data_type;
- }
+ virtual data_type getInputQuantType (uint32_t idx) const { return default_data_type; }
+ virtual data_type getOutputQuantType (uint32_t idx) const { return default_data_type; }
virtual uint32_t getSegmentsNum () const { return 0; }
virtual uint32_t getSegmentSize (uint32_t idx) const { return 0; }
virtual uint32_t getOutputSegmentIndex (uint32_t idx) const { return 0; }
virtual uint32_t getInputSegmentOffset (uint32_t idx) const { return 0; }
virtual uint32_t getOutputSegmentOffset (uint32_t idx) const { return 0; }
- virtual data_layout getInputSegmentLayout (uint32_t idx) const {
- return DATA_LAYOUT_NONE;
- }
- virtual data_layout getOutputSegmentLayout (uint32_t idx) const {
- return DATA_LAYOUT_NONE;
- }
+ virtual data_layout getInputSegmentLayout (uint32_t idx) const { return DATA_LAYOUT_NONE; }
+ virtual data_layout getOutputSegmentLayout (uint32_t idx) const { return DATA_LAYOUT_NONE; }
virtual uint32_t getInputEmodY (uint32_t idx) const { return 0; }
virtual uint32_t getInputEmodZ (uint32_t idx) const { return 0; }
uint64_t getProgramSize () const { return meta_->program_size; }
uint64_t getWeightSize () const { return meta_->weight_size; }
uint64_t getBufferSize () const { return meta_->buffer_size; }
- uint64_t getMetaSize () const {
- return NPUBIN_META_SIZE + getMetaExtendedSize ();
- }
+ uint64_t getMetaSize () const { return NPUBIN_META_SIZE + getMetaExtendedSize (); }
uint64_t getMetaExtendedSize () const {
if (meta_->extended_metasize == 0)
return NPUBIN_META_EXTENDED_SIZE (meta_->magiccode);
uint32_t getOutputOffset (uint32_t idx) const override {
return static_cast<uint32_t> (meta_->output_offset);
}
- uint32_t getInputTensorSize (uint32_t idx,
- data_layout layout) const override {
+ uint32_t getInputTensorSize (uint32_t idx, data_layout layout) const override {
return static_cast<uint32_t> (meta_->input_size);
}
- uint32_t getOutputTensorSize (uint32_t idx,
- data_layout layout) const override {
+ uint32_t getOutputTensorSize (uint32_t idx, data_layout layout) const override {
return static_cast<uint32_t> (meta_->output_size);
}
uint32_t getInputElemSize (uint32_t idx) const override { return 1; }
uint32_t getOutputElemSize (uint32_t idx) const override { return 1; }
- const uint32_t *getInputDims (uint32_t idx) const override {
- return input_dims[idx];
- }
- const uint32_t *getOutputDims (uint32_t idx) const override {
- return output_dims[idx];
- }
+ const uint32_t *getInputDims (uint32_t idx) const override { return input_dims[idx]; }
+ const uint32_t *getOutputDims (uint32_t idx) const override { return output_dims[idx]; }
- data_type getInputQuantType (uint32_t idx) const override {
- return DATA_TYPE_SRNPU;
- }
+ data_type getInputQuantType (uint32_t idx) const override { return DATA_TYPE_SRNPU; }
- data_type getOutputQuantType (uint32_t idx) const override {
- return DATA_TYPE_SRNPU;
- }
+ data_type getOutputQuantType (uint32_t idx) const override { return DATA_TYPE_SRNPU; }
private:
Metadata_v1 (npubin_meta *meta);
}
uint32_t getInputTensorSize (uint32_t idx, data_layout layout) const override;
- uint32_t getOutputTensorSize (uint32_t idx,
- data_layout layout) const override;
+ uint32_t getOutputTensorSize (uint32_t idx, data_layout layout) const override;
uint32_t getInputElemSize (uint32_t idx) const override {
assert (idx < getInputNum ());
uint32_t getOutputOffset (uint32_t idx) const override { return 0; }
uint32_t getInputTensorSize (uint32_t idx, data_layout layout) const override;
- uint32_t getOutputTensorSize (uint32_t idx,
- data_layout layout) const override;
+ uint32_t getOutputTensorSize (uint32_t idx, data_layout layout) const override;
uint32_t getInputElemSize (uint32_t idx) const override {
return get_data_size (getInputQuantType (idx));
assert (idx < getSegmentsNum ());
return meta_->segment_size[idx];
}
- uint32_t getWeightSegmentIndex () const override {
- return meta_->weight_seg_idx;
- }
+ uint32_t getWeightSegmentIndex () const override { return meta_->weight_seg_idx; }
uint32_t getInputSegmentIndex (uint32_t idx) const override {
assert (idx < getInputNum ());
return meta_->input_seg_idx[idx];
uint32_t getNumInsts ();
- void setConstraint (const npuConstraint &constraint) {
- constraint_ = constraint;
- }
+ void setConstraint (const npuConstraint &constraint) { constraint_ = constraint; }
int setDataInfo (const tensors_data_info *in, const tensors_data_info *out);
int setMetadata (void *data);
void setExtendedMetadata (HWmem *data) { extended_meta_ = data; }
private:
static std::atomic<uint32_t> global_model_id_; /**< global model id */
uint32_t model_id_; /**< model id */
- uint64_t internal_id_; /**< model id internally managed by the device */
+ uint64_t internal_id_; /**< model id internally managed by the device */
HWmem *weight_data_; /**< weight data */
HWmem *program_data_; /**< weight data */
HWmem *extended_meta_; /**< extended metadata */
std::unique_ptr<Metadata> meta_; /**< metadata */
- npuConstraint
- constraint_; /**< per-model constraint (e.g., timeout/priority) */
- tensors_data_info in_; /**< input tensor info. (e.g., data type/layout) */
- tensors_data_info out_; /**< output tensor info. */
+ npuConstraint constraint_; /**< per-model constraint (e.g., timeout/priority) */
+ tensors_data_info in_; /**< input tensor info. (e.g., data type/layout) */
+ tensors_data_info out_; /**< output tensor info. */
};
#endif /* __NE_MODEL_HH__ */
}
int
-ModelProfiler::getProfile (int req_id, const npu_profile_opt &opt,
- npu_profile *profile) {
+ModelProfiler::getProfile (int req_id, const npu_profile_opt &opt, npu_profile *profile) {
ProfileData *data = profile_map_.find (req_id);
if (data == nullptr)
return -ENOENT;
ModelProfiler::manipulateProfile (HWmem *extended, npu_profile *profile) {
npubin_meta_profile *meta_profile =
reinterpret_cast<npubin_meta_profile *> (extended->getData ());
- npu_profile_layer *new_layers =
- new npu_profile_layer[meta_profile->node_entry_num + 1];
+ npu_profile_layer *new_layers = new npu_profile_layer[meta_profile->node_entry_num + 1];
npu_profile_layer *unclassified = &new_layers[meta_profile->node_entry_num];
layer->start_cycles = profile->layers[i].start_cycles;
if (layer->end_cycles < profile->layers[i].end_cycles)
layer->end_cycles = profile->layers[i].end_cycles;
- layer->dram_read_bytes +=
- profile->layers[i].dram_read_bytes / node_num;
- layer->dram_write_bytes +=
- profile->layers[i].dram_write_bytes / node_num;
- layer->sram_read_bytes +=
- profile->layers[i].sram_read_bytes / node_num;
- layer->sram_write_bytes +=
- profile->layers[i].sram_write_bytes / node_num;
+ layer->dram_read_bytes += profile->layers[i].dram_read_bytes / node_num;
+ layer->dram_write_bytes += profile->layers[i].dram_write_bytes / node_num;
+ layer->sram_read_bytes += profile->layers[i].sram_read_bytes / node_num;
+ layer->sram_write_bytes += profile->layers[i].sram_write_bytes / node_num;
layer->visa_exec_seq = -1;
} else {
std::cerr << "Unable to find the node ID " << node_id << std::endl;
class ProfileData {
public:
- ProfileData (int req_id, const Model *model)
- : req_id_ (req_id), model_ (model) {}
+ ProfileData (int req_id, const Model *model) : req_id_ (req_id), model_ (model) {}
const Model *getModel () { return model_; }
void setInferMode (npu_infer_mode infer_mode) { infer_mode_ = infer_mode; }
npu_infer_mode getInferMode () const { return infer_mode_; }
- void setScheduler (const npu_scheduler &sched,
- const npu_scheduler_param &sched_param) {
+ void setScheduler (const npu_scheduler &sched, const npu_scheduler_param &sched_param) {
sched_ = sched;
sched_param_ = sched_param;
}
}
req->setSubmitted (true);
- int ret = service->submit (api_, req,
- std::bind (&Scheduler::handleCallback, this, req));
+ int ret = service->submit (api_, req, std::bind (&Scheduler::handleCallback, this, req));
if (ret != 0)
req->setSubmitted (false);
int dbuf_fd = hwmem->getDmabuf ();
if (dbuf_fd != KERNEL_INPUT_SEG && dbuf_fd != KERNEL_OUTPUT_SEG) {
reinterpret_cast<int32_t *> (getData ())[slot] = dbuf_fd;
- reinterpret_cast<uint32_t *> (getData () + getSize () / 2)[slot] =
- hwmem->getOffset ();
+ reinterpret_cast<uint32_t *> (getData () + getSize () / 2)[slot] = hwmem->getOffset ();
if (hwmem->getOffset () % SEGMENT_ALIGN != 0)
logwarn (TAG, "Segment is not aligned..?\n");
} else {
reinterpret_cast<int32_t *> (getData ())[slot] = dbuf_fd;
- reinterpret_cast<uint32_t *> (getData () + getSize () / 2)[slot] =
- hwmem->getSize ();
+ reinterpret_cast<uint32_t *> (getData () + getSize () / 2)[slot] = hwmem->getSize ();
}
}
* @note A non-zero segment offset is currently not supported
*/
int
-SegmentTable::createExternalSegment (uint32_t seg_idx, uint32_t seg_size,
- uint32_t seg_off, int dbuf_fd) {
+SegmentTable::createExternalSegment (uint32_t seg_idx, uint32_t seg_size, uint32_t seg_off,
+ int dbuf_fd) {
if (seg_off != 0) {
- logerr (TAG,
- "Non-zero segment offset is not supported for BUFFER_DMABUF\n");
+ logerr (TAG, "Non-zero segment offset is not supported for BUFFER_DMABUF\n");
return -EINVAL;
}
uint32_t idx = meta->getWeightSegmentIndex ();
uint32_t size = meta->getSegmentSize (idx);
if (meta->getWeightSize () > size) {
- logerr (TAG,
- "The size of weight (%" PRIu64
- ") is larger than segment size (%u)\n",
+ logerr (TAG, "The size of weight (%" PRIu64 ") is larger than segment size (%u)\n",
meta->getWeightSize (), size);
return -EINVAL;
}
}
int
-SegmentTable::createExternalInputSegments (const Model *model,
- const input_buffers *input) {
+SegmentTable::createExternalInputSegments (const Model *model, const input_buffers *input) {
const Metadata *meta = model->getMetadata ();
if (input == nullptr)
uint32_t offset = meta->getInputSegmentOffset (i);
uint32_t size = meta->getSegmentSize (idx);
- int status =
- createExternalSegment (idx, size, offset, input->bufs[i].dmabuf);
+ int status = createExternalSegment (idx, size, offset, input->bufs[i].dmabuf);
if (status != 0)
return status;
}
}
int
-SegmentTable::createExternalOutputSegments (const Model *model,
- const output_buffers *output) {
+SegmentTable::createExternalOutputSegments (const Model *model, const output_buffers *output) {
const Metadata *meta = model->getMetadata ();
if (output == nullptr || output->num_buffers == 0)
uint32_t offset = meta->getOutputSegmentOffset (i);
uint32_t size = meta->getSegmentSize (idx);
- int status =
- createExternalSegment (idx, size, offset, output->bufs[i].dmabuf);
+ int status = createExternalSegment (idx, size, offset, output->bufs[i].dmabuf);
if (status != 0)
return status;
}
uint32_t size = meta->getSegmentSize (idx);
status = createSegment (idx, size);
if (status != 0) {
- logerr (TAG, "Failed to allocate %uth segment with size %u: %d\n", idx,
- size, status);
+ logerr (TAG, "Failed to allocate %uth segment with size %u: %d\n", idx, size, status);
goto err_clear;
}
}
return nullptr;
if (idx >= num_weight_segments_) {
- logerr (TAG, "Invalid weight segment index (%u). Should be less than %u\n",
- idx, num_weight_segments_);
+ logerr (TAG, "Invalid weight segment index (%u). Should be less than %u\n", idx,
+ num_weight_segments_);
return nullptr;
}
}
if (idx >= num_input_segments_) {
- logerr (TAG, "Invalid input segment index (%u). Should be less than %u\n",
- idx, num_input_segments_);
+ logerr (TAG, "Invalid input segment index (%u). Should be less than %u\n", idx,
+ num_input_segments_);
return nullptr;
}
}
if (idx >= num_output_segments_) {
- logerr (TAG, "Invalid output segment index (%u). Should be less than %u\n",
- idx, num_output_segments_);
+ logerr (TAG, "Invalid output segment index (%u). Should be less than %u\n", idx,
+ num_output_segments_);
return nullptr;
}
}
if (idx >= num_input_segments_) {
- logerr (TAG, "Invalid input segment index (%u). Should be less than %u\n",
- idx, num_input_segments_);
+ logerr (TAG, "Invalid input segment index (%u). Should be less than %u\n", idx,
+ num_input_segments_);
return 0;
}
}
if (idx >= num_output_segments_) {
- logerr (TAG, "Invalid output segment index (%u). Should be less than %u\n",
- idx, num_output_segments_);
+ logerr (TAG, "Invalid output segment index (%u). Should be less than %u\n", idx,
+ num_output_segments_);
return 0;
}
~SegmentTable ();
/** Override alloc () and DO NOT support a variable-sized segment table */
- int alloc (size_t = 0) {
- return static_cast<HWmem *> (this)->alloc (PAGE_SIZE);
- }
+ int alloc (size_t = 0) { return static_cast<HWmem *> (this)->alloc (PAGE_SIZE); }
int createSegments (const Model *model, const input_buffers *input,
const output_buffers *output = nullptr);
int restoreSegments (void);
- HWmem *getWeightSegment (
- uint32_t idx = 0); /** maybe, # weight segments is 1 */
+ HWmem *getWeightSegment (uint32_t idx = 0); /** maybe, # weight segments is 1 */
HWmem *getInputSegment (uint32_t idx);
HWmem *getOutputSegment (uint32_t idx);
void updateSegmentSlot (HWmem *hwmem, int slot);
int createSegment (uint32_t seg_idx, uint32_t seg_size);
- int createExternalSegment (uint32_t seg_idx, uint32_t seg_size,
- uint32_t seg_off, int dbuf_fd);
+ int createExternalSegment (uint32_t seg_idx, uint32_t seg_size, uint32_t seg_off, int dbuf_fd);
int createWeightSegment (const Model *model);
- int createExternalInputSegments (const Model *model,
- const input_buffers *input);
- int createExternalOutputSegments (const Model *model,
- const output_buffers *output);
+ int createExternalInputSegments (const Model *model, const input_buffers *input);
+ int createExternalOutputSegments (const Model *model, const output_buffers *output);
std::vector<std::unique_ptr<HWmem>> segments_; /**< segments */
ThreadPool::ThreadPool () : stop_ (false) {
/** create workers with the number of threads configured */
num_threads_ = (Conf::getInstance ().getNumThreads ());
- for (uint32_t i = 0; i < num_threads_; i++)
- threads_.emplace_back ([this]() { this->worker (); });
+ for (uint32_t i = 0; i < num_threads_; i++) threads_.emplace_back ([this]() { this->worker (); });
}
/** @brief destructor of thread pool */
std::deque<std::unique_ptr<ThreadTask>>::iterator it;
uint32_t task_id = task->getID ();
- it = std::find_if (queue_.begin (), queue_.end (),
- [&task_id](const std::unique_ptr<ThreadTask>& t) {
- return t->getID () == task_id;
- });
+ it = std::find_if (
+ queue_.begin (), queue_.end (),
+ [&task_id](const std::unique_ptr<ThreadTask>& t) { return t->getID () == task_id; });
/** does not allow the same ID */
if (it != queue_.end ())
return -EBUSY;
std::unique_lock<std::mutex> lock (m_);
std::deque<std::unique_ptr<ThreadTask>>::iterator it;
- it = std::find_if (queue_.begin (), queue_.end (),
- [&task_id](const std::unique_ptr<ThreadTask>& task) {
- return task->getID () == task_id;
- });
+ it = std::find_if (
+ queue_.begin (), queue_.end (),
+ [&task_id](const std::unique_ptr<ThreadTask>& task) { return task->getID () == task_id; });
if (it == queue_.end ())
return -EBUSY;
/** the below needs a pre-acquired lock */
bool should_stop () { return stop_; }
- static std::unique_ptr<ThreadPool>
- instance_; /**< thread pool singleton instance */
- static std::once_flag once_flag_; /**< call once */
+ static std::unique_ptr<ThreadPool> instance_; /**< thread pool singleton instance */
+ static std::once_flag once_flag_; /**< call once */
std::mutex m_; /**< mutex for sync */
std::condition_variable cv_; /**< cond for sync */
* @brief DriverAPI constructor
*/
DriverAPI::DriverAPI (int dev_id)
- : dev_id_ (dev_id),
- dev_fd_ (-1) /* not opened yet */,
- initialized_ (false) {}
+ : dev_id_ (dev_id), dev_fd_ (-1) /* not opened yet */, initialized_ (false) {}
/**
* @brief get number of available devices with the given type
virtual ~DriverAPI () {}
static int getNumDevices (dev_type type);
- static std::unique_ptr<DriverAPI> createDriverAPI (dev_type type,
- int device_id);
+ static std::unique_ptr<DriverAPI> createDriverAPI (dev_type type, int device_id);
static uint32_t getCompiledAPILevel () { return api_level_; }
int getDeviceID () const { return dev_id_; }
int getDeviceFD () const { return dev_fd_; }
/** The below requires initialized device */
/** @brief check whether the device is ready (true) or busy (false) */
- virtual device_state_t isReady () const {
- return device_state_t::TRINITY_STATE_UNKNOWN;
- }
+ virtual device_state_t isReady () const { return device_state_t::TRINITY_STATE_UNKNOWN; }
/** @brief return a number of requests submitted */
virtual uint32_t numRequests () const { return 0; }
/** @brief allocate memory with the given size. return dmabuf fd */
- virtual int alloc (size_t size, bool contiguous = false) const {
- return -EPERM;
- }
+ virtual int alloc (size_t size, bool contiguous = false) const { return -EPERM; }
/** @brief deallocate memory with the corresponding dmabuf fd */
- virtual int dealloc (int dmabuf, bool contiguous = false) const {
- return -EPERM;
- }
+ virtual int dealloc (int dmabuf, bool contiguous = false) const { return -EPERM; }
/** @brief get memory status */
- virtual int getMemoryStatus (size_t *alloc, size_t *free) const {
- return -EPERM;
- }
+ virtual int getMemoryStatus (size_t *alloc, size_t *free) const { return -EPERM; }
/** @brief do mmap() for the dmabuf fd */
virtual void *mmap (int dmabuf, size_t size) const { return nullptr; }
virtual int stop_target (int id) const { return -EPERM; }
/** @brief register model config to the driver */
- virtual int registerModel (model_config_t *model,
- uint64_t npu_version = 0) const {
+ virtual int registerModel (model_config_t *model, uint64_t npu_version = 0) const {
return -EPERM;
}
virtual int deregisterModel (unsigned long long id) const { return -EPERM; }
#ifdef __FPGA__
- virtual int fpga_memcpy (int dmabuf, uint32_t offset, void *addr,
- size_t size) const {
+ virtual int fpga_memcpy (int dmabuf, uint32_t offset, void *addr, size_t size) const {
return -EPERM;
}
#endif
/** @brief get profile data for vISA instructions */
- virtual int getProfile (int req_id, npu_profile *profile) const {
- return -EPERM;
- }
+ virtual int getProfile (int req_id, npu_profile *profile) const { return -EPERM; }
virtual int getStatApps (npu_stat_apps *stat) const { return -EPERM; }
- virtual int getStatReqs (int appid, npu_stat_reqs *stat) const {
- return -EPERM;
- }
+ virtual int getStatReqs (int appid, npu_stat_reqs *stat) const { return -EPERM; }
protected:
int dev_id_; /**< device id. assume that 0 <= id < getNUmDevices() */
prof_path_ = prof_path + ".rec";
setMute (true);
- run_triv2_emul (prog, segt, metadata, cmd_path.c_str (),
- prof_path.c_str ());
+ run_triv2_emul (prog, segt, metadata, cmd_path.c_str (), prof_path.c_str ());
setMute (false);
delete[] segt;
profile->prof_path = strdup (prof_path_.c_str ());
if (!profile->prof_path) {
- std::cerr << "Unable to duplicate the profile path " << prof_path_
- << "\n";
+ std::cerr << "Unable to duplicate the profile path " << prof_path_ << "\n";
return false;
}
if (head.fmt_vesion != TRIV2PROF_FMT_VER) {
std::cerr << "Profile data format mismatch: "
- << "(" << head.fmt_vesion << " vs. " << TRIV2PROF_FMT_VER
- << ")\n";
+ << "(" << head.fmt_vesion << " vs. " << TRIV2PROF_FMT_VER << ")\n";
return false;
}
layer->visa_opcode = 0x02;
snprintf (layer->name, NPU_OPNAME_MAX, "%s", "ADMA_IN");
- layer->dram_read_bytes =
- nna_dma.src_addr_end - nna_dma.src_addr_start;
- layer->sram_write_bytes =
- nna_dma.dest_addr_end - nna_dma.dest_addr_start;
+ layer->dram_read_bytes = nna_dma.src_addr_end - nna_dma.src_addr_start;
+ layer->sram_write_bytes = nna_dma.dest_addr_end - nna_dma.dest_addr_start;
break;
case TRIV2PROF_BLOCKID_NNA_DMA_OUT:
ifs.read ((char *) &nna_dma, sizeof (T2PF_DUMP_DMA));
layer->visa_opcode = 0x03;
snprintf (layer->name, NPU_OPNAME_MAX, "%s", "ADMA_OUT");
- layer->dram_write_bytes =
- nna_dma.dest_addr_end - nna_dma.dest_addr_start;
- layer->sram_read_bytes =
- nna_dma.src_addr_end - nna_dma.src_addr_start;
+ layer->dram_write_bytes = nna_dma.dest_addr_end - nna_dma.dest_addr_start;
+ layer->sram_read_bytes = nna_dma.src_addr_end - nna_dma.src_addr_start;
break;
case TRIV2PROF_BLOCKID_DSP:
ifs.read ((char *) &dsp, sizeof (T2PF_DUMP_DSP));
layer->visa_opcode = 0x40;
snprintf (layer->name, NPU_OPNAME_MAX, "%s", "PDMA_IN");
- layer->dram_read_bytes =
- dsp_dma.src_addr_end - dsp_dma.src_addr_start;
- layer->sram_write_bytes =
- dsp_dma.dest_addr_end - dsp_dma.dest_addr_start;
+ layer->dram_read_bytes = dsp_dma.src_addr_end - dsp_dma.src_addr_start;
+ layer->sram_write_bytes = dsp_dma.dest_addr_end - dsp_dma.dest_addr_start;
break;
case TRIV2PROF_BLOCKID_DSP_DMA_OUT:
ifs.read ((char *) &dsp_dma, sizeof (T2PF_DUMP_DMA));
layer->visa_opcode = 0x41;
snprintf (layer->name, NPU_OPNAME_MAX, "%s", "PDMA_OUT");
- layer->dram_write_bytes =
- dsp_dma.dest_addr_end - dsp_dma.dest_addr_start;
- layer->sram_read_bytes =
- dsp_dma.src_addr_end - dsp_dma.src_addr_start;
+ layer->dram_write_bytes = dsp_dma.dest_addr_end - dsp_dma.dest_addr_start;
+ layer->sram_read_bytes = dsp_dma.src_addr_end - dsp_dma.src_addr_start;
break;
default:
- std::cerr << "Unknown block id detected: " << common.block_id
- << std::endl;
+ std::cerr << "Unknown block id detected: " << common.block_id << std::endl;
delete[] profile->layers;
profile->layers = nullptr;
ifs.close ();
void *getAddr () const { return addr_; }
size_t getSize () const { return size_; }
- void setModelConfig (model_config_t *model) {
- model_config_map_.insert (model->id, model);
- }
+ void setModelConfig (model_config_t *model) { model_config_map_.insert (model->id, model); }
- model_config_t *getModelConfig (uint64_t id) {
- return model_config_map_.find (id);
- }
+ model_config_t *getModelConfig (uint64_t id) { return model_config_map_.find (id); }
void unsetModelConfig (uint64_t id) { model_config_map_.remove (id); }
* @brief constructor of emulation API driver
* @param[in] dev_id device id. device id is used to emulate device fd
*/
-TrinityEmulAPI::TrinityEmulAPI (int dev_id, dev_type type)
- : DriverAPI (dev_id), dev_type_ (type) {
+TrinityEmulAPI::TrinityEmulAPI (int dev_id, dev_type type) : DriverAPI (dev_id), dev_type_ (type) {
prefix_share_ = Conf::getInstance ().getPrefixShare ();
prefix_profile_ = Conf::getInstance ().getPrefixProfile ();
}
* @return 0 if no error. otherwise a negatice error value
*/
int
-TrinityEmulAPI::getMemoryStatus (size_t *alloc_total,
- size_t *free_total) const {
+TrinityEmulAPI::getMemoryStatus (size_t *alloc_total, size_t *free_total) const {
if (!initialized ())
return -EPERM;
* @return 0 if no error. otherwise a negative errno
*/
int
-TrinityEmulAPI::registerModel (model_config_t *model_config,
- uint64_t npu_version) const {
+TrinityEmulAPI::registerModel (model_config_t *model_config, uint64_t npu_version) const {
static std::atomic<uint64_t> global_internal_id (0);
if (!initialized ())
char **segment_table = new char *[num_segs];
bool is_kernel = false;
+ /* Reconstruct the segment table for libmrpsim */
for (uint32_t i = 0; i < num_segs; i++) {
int32_t dmabuf = reinterpret_cast<int32_t *> (addr_input)[i];
- uint32_t offset = reinterpret_cast<uint32_t *> (
- addr_input + elem_input->getSize () / 2)[i];
+ uint32_t offset = reinterpret_cast<uint32_t *> (addr_input + elem_input->getSize () / 2)[i];
- /** Check it's a kernel request */
+ /* Check it's a kernel request */
if (input_config->input_mode != TRINITY_INPUT_HW) {
EmulElement *elem = elem_map_.find (dmabuf);
if (elem == nullptr) {
return -EINVAL;
}
- /** Here, set virtual address for emulations */
+ /* Here, set virtual address for emulations */
segment_table[i] = static_cast<char *> (elem->getAddr ()) + offset;
} else {
is_kernel = true;
}
}
- std::string cmd_path (prefix_share_);
-
- if (elem_model->getNpuTops () == 2)
- cmd_path += "/mRPsim/triv2_2tops.cmd";
- else
- cmd_path += "/mRPsim/triv2.cmd";
-
int req_id = input_config->req_id;
EmulReq *req = req_map_.find (req_id);
if (req != nullptr)
return status;
}
- std::string prof_path (prefix_profile_);
-
- prof_path += "/ne_profile." + std::to_string (req_id);
+ if (is_kernel) {
+ /* skip execution of kernel requests */
+ delete[] segment_table;
+ } else {
+ std::string cmd_path (prefix_share_);
+ if (elem_model->getNpuTops () == 2)
+ cmd_path += "/mRPsim/triv2_2tops.cmd";
+ else
+ cmd_path += "/mRPsim/triv2.cmd";
- auto func = std::bind (&EmulReq::run_emul, req, prog, segment_table,
- static_cast<char *> (elem_metadata->getAddr ()),
- cmd_path, prof_path);
+ std::string prof_path (prefix_profile_);
+ prof_path += "/ne_profile." + std::to_string (req_id);
- if (!is_kernel)
+ auto func = std::bind (&EmulReq::run_emul, req, prog, segment_table,
+ static_cast<char *> (elem_metadata->getAddr ()), cmd_path, prof_path);
req->run (func);
+ }
}
return 0;
* @brief constructor of the API instance for Trinity Vision driver
* @param[in] dev_id device id
*/
-TrinityVision2API::TrinityVision2API (int dev_id)
- : DriverAPI (dev_id), is_cuse_ (false) {
+TrinityVision2API::TrinityVision2API (int dev_id) : DriverAPI (dev_id), is_cuse_ (false) {
int num_devs;
if (dev_id > max_num_devs) {
return -ENODEV;
}
- path = "/dev/" + TrinityVision2API::dev_node_base + "-" +
- std::to_string (dev_id_);
+ path = "/dev/" + TrinityVision2API::dev_node_base + "-" + std::to_string (dev_id_);
fd = ::open (path.c_str (), O_RDWR);
if (fd < 0) {
logerr (TAG, "Unable to find device node: %s\n", path.c_str ());
TrinityVision2API::checkSanity () {
int lib_ver = trinity_gen_ver (0, VER_NE_MAJOR, VER_NE_MINOR, VER_NE_EXTRA);
int min_ver = this->getDrvVersion ();
- enum trinity_dev_type type = static_cast<enum trinity_dev_type> (
- (min_ver & TRINITY_MASK_DEV) >> TRINITY_SHIFT_DEV);
+ enum trinity_dev_type type =
+ static_cast<enum trinity_dev_type> ((min_ver & TRINITY_MASK_DEV) >> TRINITY_SHIFT_DEV);
/* Check if this device is a TRIV2-compatible one */
if (type != TRINITY_DEV_VISION2 && type != TRINITY_DEV_VISION2_CUSE) {
min_ver &= ~TRINITY_MASK_DEV;
/* Check if the major version numbers are same */
- if ((lib_ver & TRINITY_MASK_MAJOR_VER) !=
- (min_ver & TRINITY_MASK_MAJOR_VER)) {
+ if ((lib_ver & TRINITY_MASK_MAJOR_VER) != (min_ver & TRINITY_MASK_MAJOR_VER)) {
logerr (TAG, "Version mismatch between driver and library\n");
return -ENOTSUP;
}
path.clear ();
for (int i = 0; i < max_num_devs; ++i) {
- path =
- "/dev/" + TrinityVision2API::dev_node_base + "-" + std::to_string (i);
+ path = "/dev/" + TrinityVision2API::dev_node_base + "-" + std::to_string (i);
ret = stat (path.c_str (), &sb);
if (ret == 0 && S_ISCHR (sb.st_mode)) {
cnt++;
if (ret == 0) {
uint32_t num_requests = 0;
- for (uint32_t i = 0; i < stat.num_apps; i++)
- num_requests += stat.stat[i].num_active_reqs;
+ for (uint32_t i = 0; i < stat.num_apps; i++) num_requests += stat.stat[i].num_active_reqs;
return num_requests;
}
struct stat statbuf;
/* Let's use shared memory for emulated dmabuf */
- shm_name =
- "/triv2_" + std::to_string (getpid ()) + "_" + std::to_string (dbuf_fd);
+ shm_name = "/triv2_" + std::to_string (getpid ()) + "_" + std::to_string (dbuf_fd);
ret = shm_open (shm_name.c_str (), O_RDWR, 0666);
if (ret < 0)
return ret;
* @return 0 if no error. otherwise a negatice error value
*/
int
-TrinityVision2API::getMemoryStatus (size_t *alloc_total,
- size_t *free_total) const {
+TrinityVision2API::getMemoryStatus (size_t *alloc_total, size_t *free_total) const {
struct trinity_ioctl_stat_app stat;
int ret;
* @return 0 if no error. otherwise a negative errno
*/
int
-TrinityVision2API::registerModel (model_config_t *model_config,
- uint64_t npu_version) const {
+TrinityVision2API::registerModel (model_config_t *model_config, uint64_t npu_version) const {
uint32_t model_tops;
uint32_t device_tops;
int ret;
model_config->metadata_dbuf_fd = meta->getDbufFD ();
}
- ret =
- ioctl (this->getDeviceFD (), TRINITY_IOCTL_REGISTER_MODEL, model_config);
+ ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_REGISTER_MODEL, model_config);
/* rollback FDs to prevent any side-effects */
if (is_cuse_) {
#ifdef __FPGA__
int
-TrinityVision2API::fpga_memcpy (int dmabuf, uint32_t offset, void *addr,
- size_t size) const {
+TrinityVision2API::fpga_memcpy (int dmabuf, uint32_t offset, void *addr, size_t size) const {
struct trinity_ioctl_fpga_memcpy fpga;
int ret;
iniparser_set_error_callback (error_callback);
/** Load up config from ini if available */
- dictionary *ini =
- iniparser_load (inipath != nullptr ? inipath : default_ini_path);
+ dictionary *ini = iniparser_load (inipath != nullptr ? inipath : default_ini_path);
if (ini) {
loadConfIni (ini);
iniparser_freedict (ini);
*/
void
Conf::loadConfIni (dictionary *ini) {
- const char *resv_mem_size =
- iniparser_getstring (ini, "main:resv_mem_size", nullptr);
- const char *num_threads =
- iniparser_getstring (ini, "main:num_threads", nullptr);
- const char *prefix_share =
- iniparser_getstring (ini, "main:prefix_share", nullptr);
- const char *prefix_profile =
- iniparser_getstring (ini, "main:prefix_profile", nullptr);
+ const char *resv_mem_size = iniparser_getstring (ini, "main:resv_mem_size", nullptr);
+ const char *num_threads = iniparser_getstring (ini, "main:num_threads", nullptr);
+ const char *prefix_share = iniparser_getstring (ini, "main:prefix_share", nullptr);
+ const char *prefix_profile = iniparser_getstring (ini, "main:prefix_profile", nullptr);
const char *log_dir = iniparser_getstring (ini, "debug:log_dir", nullptr);
const char *log_level = iniparser_getstring (ini, "debug:log_level", nullptr);
* @brief Module Name String in 8 characters
*/
static const char *modulestr[_NEND] = {
- [_N1] = "N1/CommPl", [_N11] = "N11/IP ", [_N2] = "N2/Handlr",
- [_N21] = "N21/Host ", [_N3] = "N3/Sched ", [_N4] = "N4/InputC",
- [_N41] = "N41/HWrec", [_N42] = "N42/Host ", [_N5] = "N5/ThPool",
- [_N6] = "N6/Mem ", [_N61] = "N61/MemDe", [_N62] = "N62/MemPl",
- [_N7] = "N7/HWmem ", [_N71] = "N71/Model", [_N72] = "N72/Buff ",
- [_N73] = "N72/Segt ", [_N8] = "N8/HWmemI", [_N9] = "N9/NPUdrv",
- [_N91] = "N91/TRIV ", [_N92] = "N92/TRIV2", [_N93] = "N93/TRIA ",
- [_N94] = "N94/Emul ",
+ [_N1] = "N1/CommPl", [_N11] = "N11/IP ", [_N2] = "N2/Handlr", [_N21] = "N21/Host ",
+ [_N3] = "N3/Sched ", [_N4] = "N4/InputC", [_N41] = "N41/HWrec", [_N42] = "N42/Host ",
+ [_N5] = "N5/ThPool", [_N6] = "N6/Mem ", [_N61] = "N61/MemDe", [_N62] = "N62/MemPl",
+ [_N7] = "N7/HWmem ", [_N71] = "N71/Model", [_N72] = "N72/Buff ", [_N73] = "N72/Segt ",
+ [_N8] = "N8/HWmemI", [_N9] = "N9/NPUdrv", [_N91] = "N91/TRIV ", [_N92] = "N92/TRIV2",
+ [_N93] = "N93/TRIA ", [_N94] = "N94/Emul ",
};
/** @brief singleton instance */
}
int
-Logger::logwrite_args (npu_loglevel l, const char *tag, const char *format,
- va_list args) {
+Logger::logwrite_args (npu_loglevel l, const char *tag, const char *format, va_list args) {
std::unique_lock<std::mutex> lock (m_);
time_t ltime = time (nullptr);
time_str[strcspn (time_str, "\n")] = '\x00';
char log_msg[MAX_LOG_MSG];
- int log_len = snprintf (log_msg, MAX_LOG_MSG, "[%s][%s][%s] ", loglevelstr[l],
- tag, time_str);
+ int log_len = snprintf (log_msg, MAX_LOG_MSG, "[%s][%s][%s] ", loglevelstr[l], tag, time_str);
log_len += vsnprintf (log_msg + log_len, MAX_LOG_MSG - log_len, format, args);
if (fp_ == nullptr) {
char filename[FILENAME_MAX];
- snprintf (filename, FILENAME_MAX, "%s/%s",
- Conf::getInstance ().getLogDir (), LOG_FILENAME);
+ snprintf (filename, FILENAME_MAX, "%s/%s", Conf::getInstance ().getLogDir (), LOG_FILENAME);
fp_ = fopen (filename, "a");
if (fp_ == nullptr)
return -errno;
static Logger &getInstance ();
int logwrite (npu_loglevel l, module m, const char *format, ...);
- int logwrite_args (npu_loglevel l, const char *tag, const char *format,
- va_list args);
+ int logwrite_args (npu_loglevel l, const char *tag, const char *format, va_list args);
~Logger ();
};
/** @brief log macros with different log levels */
-#define __FILENAME__ \
- (strrchr (__FILE__, '/') ? strrchr (__FILE__, '/') + 1 : __FILE__)
-#define logerr(m, fmt, ...) \
- Logger::getInstance ().logwrite (NPU_LOG_ERROR, m, "(%s:%d) " fmt, \
- __FILENAME__, __LINE__, ##__VA_ARGS__)
-#define logwarn(m, fmt, ...) \
- Logger::getInstance ().logwrite (NPU_LOG_WARN, m, "(%s:%d) " fmt, \
- __FILENAME__, __LINE__, ##__VA_ARGS__)
-#define loginfo(m, fmt, ...) \
- Logger::getInstance ().logwrite (NPU_LOG_INFO, m, "(%s:%d) " fmt, \
- __FILENAME__, __LINE__, ##__VA_ARGS__)
+#define __FILENAME__ (strrchr (__FILE__, '/') ? strrchr (__FILE__, '/') + 1 : __FILE__)
+#define logerr(m, fmt, ...) \
+ Logger::getInstance ().logwrite (NPU_LOG_ERROR, m, "(%s:%d) " fmt, __FILENAME__, __LINE__, \
+ ##__VA_ARGS__)
+#define logwarn(m, fmt, ...) \
+ Logger::getInstance ().logwrite (NPU_LOG_WARN, m, "(%s:%d) " fmt, __FILENAME__, __LINE__, \
+ ##__VA_ARGS__)
+#define loginfo(m, fmt, ...) \
+ Logger::getInstance ().logwrite (NPU_LOG_INFO, m, "(%s:%d) " fmt, __FILENAME__, __LINE__, \
+ ##__VA_ARGS__)
/** @brief thread-safe map */
template <typename K, typename V>
/** @brief insert element to the map */
int insert (K key, V *value) {
std::unique_lock<std::mutex> lock (m_);
- auto status =
- map_.insert (std::make_pair (key, std::unique_ptr<V> (value)));
+ auto status = map_.insert (std::make_pair (key, std::unique_ptr<V> (value)));
if (status.second == false)
return -EINVAL;
* @note Internal data of npu_profile is valid until putNPU_profile is called
*/
int
-getNPU_profile_opt (npudev_h dev, int req_id, const npu_profile_opt opt,
- npu_profile *profile) {
+getNPU_profile_opt (npudev_h dev, int req_id, const npu_profile_opt opt, npu_profile *profile) {
INIT_HOST_HANDLER (host_handler, dev);
return host_handler->getProfile (req_id, opt, profile);
* @return 0 if no error. otherwise a negative error value
*/
int
-getNPUmodel_tensorSize (npudev_h dev, uint32_t model_id, bool input,
- uint32_t index, uint32_t *size) {
+getNPUmodel_tensorSize (npudev_h dev, uint32_t model_id, bool input, uint32_t index,
+ uint32_t *size) {
INIT_HOST_HANDLER (host_handler, dev);
return host_handler->getTensorSize (model_id, input, index, size);
* to avoid unnecessary memcpy. Make sure that they have 'BUFFER_DMABUF' types.
*/
int
-runNPU_model (npudev_h dev, uint32_t modelid, npu_infer_mode mode,
- const input_buffers *input, output_buffers *output,
- npuOutputNotify cb, void *data) {
+runNPU_model (npudev_h dev, uint32_t modelid, npu_infer_mode mode, const input_buffers *input,
+ output_buffers *output, npuOutputNotify cb, void *data) {
INIT_HOST_HANDLER (host_handler, dev);
return host_handler->runModel (modelid, mode, input, output, cb, data);
* @detail There is a memcpy for the output buffer.
*/
int
-runNPU_sync (npudev_h dev, uint32_t modelid, const input_buffers *input,
- output_buffers *output) {
+runNPU_sync (npudev_h dev, uint32_t modelid, const input_buffers *input, output_buffers *output) {
/* runNPU_sync() assumes that output_buffers is filled by npu-engine */
memset (output, '\x00', sizeof (output_buffers));
- return runNPU_model (dev, modelid, NPU_INFER_BLOCKING, input, output, nullptr,
- nullptr);
+ return runNPU_model (dev, modelid, NPU_INFER_BLOCKING, input, output, nullptr, nullptr);
}
/**
* @detail There is a memcpy for the output buffer.
*/
int
-runNPU_async (npudev_h dev, uint32_t modelid, const input_buffers *input,
- npuOutputNotify cb, uint64_t *sequence, void *data,
- npu_async_mode mode) {
- return runNPU_model (dev, modelid, NPU_INFER_NON_BLOCKING, input, nullptr, cb,
- data);
+runNPU_async (npudev_h dev, uint32_t modelid, const input_buffers *input, npuOutputNotify cb,
+ uint64_t *sequence, void *data, npu_async_mode mode) {
+ return runNPU_model (dev, modelid, NPU_INFER_NON_BLOCKING, input, nullptr, cb, data);
}
/**
* internally (e.g., NHWC <-> TRIV2).
*/
int
-setNPU_requestData (npudev_h dev, int req_id, input_buffers *input,
- tensors_data_info *in_info, output_buffers *output,
- tensors_data_info *out_info) {
+setNPU_requestData (npudev_h dev, int req_id, input_buffers *input, tensors_data_info *in_info,
+ output_buffers *output, tensors_data_info *out_info) {
INIT_HOST_HANDLER (host_handler, dev);
- return host_handler->setRequestData (req_id, input, in_info, output,
- out_info);
+ return host_handler->setRequestData (req_id, input, in_info, output, out_info);
}
/**
* @return 0 if no error. Otherwise a negative errno
*/
int
-setNPU_requestCallback (npudev_h dev, int req_id, npuOutputNotify cb,
- void *data) {
+setNPU_requestCallback (npudev_h dev, int req_id, npuOutputNotify cb, void *data) {
INIT_HOST_HANDLER (host_handler, dev);
return host_handler->setRequestCallback (req_id, cb, data);
return status;
for (uint32_t i = 0; i < repeat_; i++) {
- status = runNPU_async (dev_, model_id_, &input_, callback, NULL, this,
- NPUASYNC_WAIT);
+ status = runNPU_async (dev_, model_id_, &input_, callback, NULL, this, NPUASYNC_WAIT);
if (status < 0)
return status;
}
/** TRIV2 requires segment table */
meta.segment_num = 3;
- for (uint32_t idx = 0; idx < meta.segment_num; idx++)
- meta.segment_size[idx] = segment_size;
+ for (uint32_t idx = 0; idx < meta.segment_num; idx++) meta.segment_size[idx] = segment_size;
meta.weight_seg_idx = 0;
/** TRIV2 requires segment table */
meta.segment_num = 3;
- for (uint32_t idx = 0; idx < meta.segment_num; idx++)
- meta.segment_size[idx] = segment_size;
+ for (uint32_t idx = 0; idx < meta.segment_num; idx++) meta.segment_size[idx] = segment_size;
meta.weight_seg_idx = 0;
return status;
}
- return UtilTRIV2::loadModel (model_dir, &model_id_, NPU_PRIORITY_MID,
- NPU_TIMEOUT_MS);
+ return UtilTRIV2::loadModel (model_dir, &model_id_, NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
}
/** @brief run the inference */
return;
if (alloc_total != free_total)
- cerr << "Possible memory leak..? (" << alloc_total << " vs. "
- << free_total << ")\n";
+ cerr << "Possible memory leak..? (" << alloc_total << " vs. " << free_total << ")\n";
}
/** @brief configure testing mode */
for (uint32_t i = 0; i < num_iter_; i++) {
PRINT_STATUS_ITERS (i, num_iter_);
- status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID,
- NPU_TIMEOUT_MS);
+ status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
if (status != 0)
return status;
status = test_ret_success;
} else if (mode_ == AGING_TEST_INFERENCE) {
/* repeat model_inference only */
- status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID,
- NPU_TIMEOUT_MS);
+ status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
if (status != 0)
return status;
for (uint32_t i = 0; i < num_iter_; i++) {
PRINT_STATUS_ITERS (i, num_iter_);
- status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID,
- NPU_TIMEOUT_MS);
+ status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
if (status != 0)
return status;
return status;
}
- status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID,
- NPU_TIMEOUT_MS);
+ status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
if (status != 0)
return status;
return status;
}
- return UtilTRIV2::loadModel (model_dir, &model_id_, NPU_PRIORITY_MID,
- NPU_TIMEOUT_MS);
+ return UtilTRIV2::loadModel (model_dir, &model_id_, NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
}
/** @brief run the inference */
/** @brief c++ class to describe how to use npu-engine library */
class TesterTRIV2 {
public:
- TesterTRIV2 ()
- : dev_ (nullptr), dev_tmp_ (nullptr), meta_ (nullptr), model_id_ (0) {
+ TesterTRIV2 () : dev_ (nullptr), dev_tmp_ (nullptr), meta_ (nullptr), model_id_ (0) {
memset (&input_, '\x00', sizeof (input_buffers));
memset (&input_tmp_, '\x00', sizeof (input_buffers));
}
size_t size = ifs.tellg ();
ifs.seekg (0);
- ifs.read (static_cast<char *> (input_tmp_.bufs[idx].addr) + input_seg_off,
- size);
+ ifs.read (static_cast<char *> (input_tmp_.bufs[idx].addr) + input_seg_off, size);
ifs.close ();
input_.bufs[idx].type = BUFFER_DMABUF;
}
for (int j = 0; j < num_models; j++) {
- status = testers[j].loadModel (model_paths[j].c_str (), &model_ids[j],
- NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
+ status = testers[j].loadModel (model_paths[j].c_str (), &model_ids[j], NPU_PRIORITY_MID,
+ NPU_TIMEOUT_MS);
if (status != 0) {
cerr << "Unable to load model\n";
is_error = true;
return status;
}
- status =
- UtilTRIV2::loadModel (models_dir + "/" + MID_MODEL_NAME, &mid_model_id_,
- NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
+ status = UtilTRIV2::loadModel (models_dir + "/" + MID_MODEL_NAME, &mid_model_id_,
+ NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
if (status != test_ret_success) {
cerr << "Failed to find a model: " << MID_MODEL_NAME << "\n";
return status;
}
- status = UtilTRIV2::loadModel (models_dir + "/" + HIGH_MODEL_NAME,
- &high_model_id_, NPU_PRIORITY_HIGH,
- NPU_TIMEOUT_MS);
+ status = UtilTRIV2::loadModel (models_dir + "/" + HIGH_MODEL_NAME, &high_model_id_,
+ NPU_PRIORITY_HIGH, NPU_TIMEOUT_MS);
if (status != test_ret_success) {
cerr << "Failed to find a model: " << HIGH_MODEL_NAME << "\n";
return status;
return status;
}
- return UtilTRIV2::loadModel (model_dir, &model_id_, NPU_PRIORITY_MID,
- NPU_TIMEOUT_MS);
+ return UtilTRIV2::loadModel (model_dir, &model_id_, NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
}
/** @brief run the inference */
cerr << "Profile Path : " << profile.prof_path << "\n";
cerr << "Total System Cycles : " << profile.total_system_cycles << "\n";
if (profile.dram_input_footprint > 0)
- cerr << "DRAM Input Footprint (KB) : "
- << (profile.dram_input_footprint >> 10) << "\n";
+ cerr << "DRAM Input Footprint (KB) : " << (profile.dram_input_footprint >> 10) << "\n";
if (profile.dram_output_footprint > 0)
- cerr << "DRAM Output Footprint (KB) : "
- << (profile.dram_output_footprint >> 10) << "\n";
+ cerr << "DRAM Output Footprint (KB) : " << (profile.dram_output_footprint >> 10) << "\n";
if (profile.layers != nullptr) {
cerr << "\n";
for (uint32_t i = 0; i < profile.num_layers; i++) {
cerr << "[" << i << "] " << profile.layers[i].name << "\n";
if (profile.layers[i].running_cycles > 0)
- cerr << "\tRunning Cycles : " << profile.layers[i].running_cycles
- << "\n";
+ cerr << "\tRunning Cycles : " << profile.layers[i].running_cycles << "\n";
if (profile.layers[i].start_cycles > 0)
- cerr << "\tStart Cycles : " << profile.layers[i].start_cycles
- << "\n";
+ cerr << "\tStart Cycles : " << profile.layers[i].start_cycles << "\n";
if (profile.layers[i].end_cycles > 0)
cerr << "\tEnd Cycles : " << profile.layers[i].end_cycles << "\n";
if (profile.layers[i].dram_read_bytes > 0)
- cerr << "\tDRAM Read (KB) : "
- << (profile.layers[i].dram_read_bytes >> 10) << "\n";
+ cerr << "\tDRAM Read (KB) : " << (profile.layers[i].dram_read_bytes >> 10) << "\n";
if (profile.layers[i].dram_write_bytes > 0)
- cerr << "\tDRAM Write (KB) : "
- << (profile.layers[i].dram_write_bytes >> 10) << "\n";
+ cerr << "\tDRAM Write (KB) : " << (profile.layers[i].dram_write_bytes >> 10) << "\n";
if (profile.layers[i].sram_read_bytes > 0)
- cerr << "\tSRAM Read (KB) : "
- << (profile.layers[i].sram_read_bytes >> 10) << "\n";
+ cerr << "\tSRAM Read (KB) : " << (profile.layers[i].sram_read_bytes >> 10) << "\n";
if (profile.layers[i].sram_write_bytes > 0)
- cerr << "\tSRAM Write (KB) : "
- << (profile.layers[i].sram_write_bytes >> 10) << "\n";
+ cerr << "\tSRAM Write (KB) : " << (profile.layers[i].sram_write_bytes >> 10) << "\n";
if (profile.layers[i].visa_exec_seq > 0)
- cerr << "\tvISA Exec Seq : " << profile.layers[i].visa_exec_seq
- << "\n";
+ cerr << "\tvISA Exec Seq : " << profile.layers[i].visa_exec_seq << "\n";
}
}
cerr << "Profile Path : " << profile.prof_path << "\n";
cerr << "Total System Cycles : " << profile.total_system_cycles << "\n";
if (profile.dram_input_footprint > 0)
- cerr << "DRAM Input Footprint (KB) : "
- << (profile.dram_input_footprint >> 10) << "\n";
+ cerr << "DRAM Input Footprint (KB) : " << (profile.dram_input_footprint >> 10) << "\n";
if (profile.dram_output_footprint > 0)
- cerr << "DRAM Output Footprint (KB) : "
- << (profile.dram_output_footprint >> 10) << "\n";
+ cerr << "DRAM Output Footprint (KB) : " << (profile.dram_output_footprint >> 10) << "\n";
if (profile.layers != nullptr) {
cerr << "\n";
for (uint32_t i = 0; i < profile.num_layers; i++) {
cerr << "[" << i << "] " << profile.layers[i].name << "\n";
if (profile.layers[i].running_cycles > 0)
- cerr << "\tRunning Cycles : " << profile.layers[i].running_cycles
- << "\n";
+ cerr << "\tRunning Cycles : " << profile.layers[i].running_cycles << "\n";
if (profile.layers[i].start_cycles > 0)
- cerr << "\tStart Cycles : " << profile.layers[i].start_cycles
- << "\n";
+ cerr << "\tStart Cycles : " << profile.layers[i].start_cycles << "\n";
if (profile.layers[i].end_cycles > 0)
cerr << "\tEnd Cycles : " << profile.layers[i].end_cycles << "\n";
if (profile.layers[i].dram_read_bytes > 0)
- cerr << "\tDRAM Read (KB) : "
- << (profile.layers[i].dram_read_bytes >> 10) << "\n";
+ cerr << "\tDRAM Read (KB) : " << (profile.layers[i].dram_read_bytes >> 10) << "\n";
if (profile.layers[i].dram_write_bytes > 0)
- cerr << "\tDRAM Write (KB) : "
- << (profile.layers[i].dram_write_bytes >> 10) << "\n";
+ cerr << "\tDRAM Write (KB) : " << (profile.layers[i].dram_write_bytes >> 10) << "\n";
if (profile.layers[i].sram_read_bytes > 0)
- cerr << "\tSRAM Read (KB) : "
- << (profile.layers[i].sram_read_bytes >> 10) << "\n";
+ cerr << "\tSRAM Read (KB) : " << (profile.layers[i].sram_read_bytes >> 10) << "\n";
if (profile.layers[i].sram_write_bytes > 0)
- cerr << "\tSRAM Write (KB) : "
- << (profile.layers[i].sram_write_bytes >> 10) << "\n";
+ cerr << "\tSRAM Write (KB) : " << (profile.layers[i].sram_write_bytes >> 10) << "\n";
if (profile.layers[i].visa_exec_seq > 0)
- cerr << "\tvISA Exec Seq : " << profile.layers[i].visa_exec_seq
- << "\n";
+ cerr << "\tvISA Exec Seq : " << profile.layers[i].visa_exec_seq << "\n";
}
}
/** @brief c++ class to describe how to use npu-engine library */
class TesterTRIV2 {
public:
- TesterTRIV2 () : dev_ (nullptr), meta_ (nullptr), model_id_ (0) {
- loop_ = DEFAULT_LOOPS;
- }
+ TesterTRIV2 () : dev_ (nullptr), meta_ (nullptr), model_id_ (0) { loop_ = DEFAULT_LOOPS; }
~TesterTRIV2 () {
/** release resources */
if (status != 0)
return status;
- int id = runNPU_internalInput (dev_, model_id_, NPUINPUT_HW_RECURRING,
- hw_dev_.c_str ());
+ int id = runNPU_internalInput (dev_, model_id_, NPUINPUT_HW_RECURRING, hw_dev_.c_str ());
if (id < 0)
return id;
uint32_t model_id;
int req_id;
- status =
- tester.loadModel (model_dir, &model_id, NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
+ status = tester.loadModel (model_dir, &model_id, NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
if (status != test_ret_success) {
cerr << "Unable to load model\n";
return status;
int priority = elem->IntAttribute ("priority");
int timeout = elem->IntAttribute ("timeout");
- if (priority < NPU_PRIORITY_LOW || priority > NPU_PRIORITY_HIGH ||
- timeout < 0)
+ if (priority < NPU_PRIORITY_LOW || priority > NPU_PRIORITY_HIGH || timeout < 0)
return -EINVAL;
XMLElement *item = elem->FirstChildElement ("dirpath");
if (item == nullptr)
return -EINVAL;
- if (UtilTRIV2::loadModel (item->GetText (), nullptr,
- static_cast<npu_priority> (priority),
+ if (UtilTRIV2::loadModel (item->GetText (), nullptr, static_cast<npu_priority> (priority),
timeout) != 0)
return -EINVAL;
#define STATECHANGE_TIMEOUT 100000 /* 100s */
-typedef enum {
- MODEL_CONV_2D_000 = 0,
- MODEL_MOBILENET_V1,
- MODEL_END
-} srnpu_model;
+typedef enum { MODEL_CONV_2D_000 = 0, MODEL_MOBILENET_V1, MODEL_END } srnpu_model;
static const gchar *model_names[MODEL_END] = {
[MODEL_CONV_2D_000] = "CONV_2D_000",
};
static int
-set_pipeline_state_sync (GstElement *pipeline, GstState state,
- uint32_t timeout_ms) {
+set_pipeline_state_sync (GstElement *pipeline, GstState state, uint32_t timeout_ms) {
GstState cur_state = GST_STATE_VOID_PENDING;
GstStateChangeReturn ret;
gint counter = 0;
const gchar *input_dim = input_dims[model];
const gchar *output_dim = output_dims[model];
- gchar *model_path = g_strdup_printf ("%s/testdata/TRIV235_2TOPS/%s",
- NE_DATADIR, model_names[model]);
+ gchar *model_path =
+ g_strdup_printf ("%s/testdata/TRIV235_2TOPS/%s", NE_DATADIR, model_names[model]);
gchar *pipeline = g_strdup_printf (
"filesrc location=%s/input_fmap_0.bin blocksize=-1 ! "
"application/octet-stream "
gstpipe = gst_parse_launch (pipeline, &err);
EXPECT_NE (gstpipe, nullptr);
- EXPECT_EQ (
- set_pipeline_state_sync (gstpipe, GST_STATE_PLAYING, STATECHANGE_TIMEOUT),
- 0);
- EXPECT_EQ (
- set_pipeline_state_sync (gstpipe, GST_STATE_NULL, STATECHANGE_TIMEOUT),
- 0);
+ EXPECT_EQ (set_pipeline_state_sync (gstpipe, GST_STATE_PLAYING, STATECHANGE_TIMEOUT), 0);
+ EXPECT_EQ (set_pipeline_state_sync (gstpipe, GST_STATE_NULL, STATECHANGE_TIMEOUT), 0);
gst_object_unref (gstpipe);
g_free (pipeline);
gstpipe = gst_parse_launch (pipeline, &err);
EXPECT_NE (gstpipe, nullptr);
- EXPECT_EQ (
- set_pipeline_state_sync (gstpipe, GST_STATE_PLAYING, STATECHANGE_TIMEOUT),
- 0);
- EXPECT_EQ (
- set_pipeline_state_sync (gstpipe, GST_STATE_NULL, STATECHANGE_TIMEOUT),
- 0);
+ EXPECT_EQ (set_pipeline_state_sync (gstpipe, GST_STATE_PLAYING, STATECHANGE_TIMEOUT), 0);
+ EXPECT_EQ (set_pipeline_state_sync (gstpipe, GST_STATE_NULL, STATECHANGE_TIMEOUT), 0);
gst_object_unref (gstpipe);
g_free (pipeline);
return NPUMGR_STATUS_ERR_FAIL;
}
- status = npumgr_network_create (
- context, 1, input_files, NPUMGR_BUF_TYPE_DRIVER, 1, input_tensor_names,
- NPUMGR_BUF_TYPE_DRIVER, 1, output_tensor_names, &network);
+ status =
+ npumgr_network_create (context, 1, input_files, NPUMGR_BUF_TYPE_DRIVER, 1, input_tensor_names,
+ NPUMGR_BUF_TYPE_DRIVER, 1, output_tensor_names, &network);
if (status != NPUMGR_STATUS_SUCCESS) {
cerr << "Unable to create a npumgr network, " << status << "\n";
goto destroy_ctx;
size_t read_bytes = fread (data, 1, input_bufs[i].buf_size, f);
if (read_bytes != input_bufs[i].buf_size) {
- cerr << "Unable to read input data, " << read_bytes << " vs. "
- << input_bufs[i].buf_size << "\n";
+ cerr << "Unable to read input data, " << read_bytes << " vs. " << input_bufs[i].buf_size
+ << "\n";
fclose (f);
goto destroy_all;
}
goto destroy_all;
}
- if (compare_data (file_path.c_str (), (const char *) data,
- output_bufs[i].buf_size) != 0) {
+ if (compare_data (file_path.c_str (), (const char *) data, output_bufs[i].buf_size) != 0) {
cerr << "Failed to get valid output data\n";
goto destroy_all;
}
* @brief fill dummy metadata v1
*/
static void
-fill_test_metadata_v1 (npubin_meta &data, uint32_t input_size,
- uint32_t output_size) {
+fill_test_metadata_v1 (npubin_meta &data, uint32_t input_size, uint32_t output_size) {
data.magiccode = NPUBIN_MAGICCODE | 0x1; /* v1 */
data.size = 8192;
data.buffer_size = 4096;
* @brief fill dummy metadata v2
*/
static void
-fill_test_metadata_v2 (npubin_meta &data, uint32_t input_num,
- uint32_t output_num) {
+fill_test_metadata_v2 (npubin_meta &data, uint32_t input_num, uint32_t output_num) {
data.magiccode = NPUBIN_MAGICCODE | 0x2; /* v2 */
data.size = 8192;
data.buffer_size = 4096;
for (uint32_t i = 0; i < data.input_num; i++) {
data.input_offsets[i] = 100 * (i + 1);
data.input_elem_size[i] = 1 * (i + 1);
- for (uint32_t j = 0; j < MAX_RANK - 1; j++)
- data.input_dims[i][j] = 1 * (i + 1);
+ for (uint32_t j = 0; j < MAX_RANK - 1; j++) data.input_dims[i][j] = 1 * (i + 1);
data.input_dims[i][MAX_RANK - 1] = DATA_GRANULARITY;
data.input_quant_z[i] = 3 * (i + 1);
data.input_quant_s[i] = 4 * (i + 1);
for (uint32_t i = 0; i < data.output_num; i++) {
data.output_offsets[i] = 100 * (i + 1);
data.output_elem_size[i] = 1 * (i + 1);
- for (uint32_t j = 0; j < MAX_RANK - 1; j++)
- data.output_dims[i][j] = 1 * (i + 1);
+ for (uint32_t j = 0; j < MAX_RANK - 1; j++) data.output_dims[i][j] = 1 * (i + 1);
data.output_dims[i][MAX_RANK - 1] = DATA_GRANULARITY;
data.output_quant_z[i] = 3 * (i + 1);
data.output_quant_s[i] = 4 * (i + 1);
EXPECT_EQ (plugin.insertGenericBuffer (data, &buffer), 0);
- for (size_t i = 0; i < size; i++)
- EXPECT_EQ (static_cast<char *> (buffer.addr)[i], 'a');
+ for (size_t i = 0; i < size; i++) EXPECT_EQ (static_cast<char *> (buffer.addr)[i], 'a');
/** data manipulation func is called */
- auto manip_func =
- std::bind (test_manip, static_cast<char *> (buffer.addr), size);
+ auto manip_func = std::bind (test_manip, static_cast<char *> (buffer.addr), size);
EXPECT_EQ (plugin.insertGenericBuffer (data, &buffer, manip_func), 0);
- for (size_t i = 0; i < size; i++)
- EXPECT_EQ (static_cast<char *> (buffer.addr)[i], 'b');
+ for (size_t i = 0; i < size; i++) EXPECT_EQ (static_cast<char *> (buffer.addr)[i], 'b');
delete[] static_cast<char *> (buffer.addr);
delete[] data;
for (int i = 0; i < 4096; i += granularity) {
EXPECT_EQ (
- memcmp (src_data + i, dst_data + (granularity / 2) * (i / granularity),
- granularity / 2),
+ memcmp (src_data + i, dst_data + (granularity / 2) * (i / granularity), granularity / 2),
0);
EXPECT_EQ (memcmp (src_data + i + (granularity / 2),
- dst_data + (granularity / 2) * (i / granularity) + 2048,
- granularity / 2),
+ dst_data + (granularity / 2) * (i / granularity) + 2048, granularity / 2),
0);
}
/* check values */
for (int i = 0; i < 4096; i += granularity) {
EXPECT_EQ (
- memcmp (src_data + i, dst_data + (granularity / 2) * (i / granularity),
- granularity / 2),
+ memcmp (src_data + i, dst_data + (granularity / 2) * (i / granularity), granularity / 2),
0);
EXPECT_EQ (memcmp (src_data + i + (granularity / 2),
- dst_data + (granularity / 2) * (i / granularity) + 2048,
- granularity / 2),
+ dst_data + (granularity / 2) * (i / granularity) + 2048, granularity / 2),
0);
}
for (int i = 0; i < 4096; i += granularity) {
EXPECT_EQ (
- memcmp (src_data + i, dst_data + (granularity / 4) * (i / granularity),
- granularity / 4),
+ memcmp (src_data + i, dst_data + (granularity / 4) * (i / granularity), granularity / 4),
0);
EXPECT_EQ (memcmp (src_data + i + (granularity / 4),
- dst_data + (granularity / 4) * (i / granularity) + 1024,
- granularity / 4),
+ dst_data + (granularity / 4) * (i / granularity) + 1024, granularity / 4),
0);
EXPECT_EQ (memcmp (src_data + i + 2 * (granularity / 4),
- dst_data + (granularity / 4) * (i / granularity) + 2048,
- granularity / 4),
+ dst_data + (granularity / 4) * (i / granularity) + 2048, granularity / 4),
0);
EXPECT_EQ (memcmp (src_data + i + 3 * (granularity / 4),
- dst_data + (granularity / 4) * (i / granularity) + 3072,
- granularity / 4),
+ dst_data + (granularity / 4) * (i / granularity) + 3072, granularity / 4),
0);
}
* @brief Test quantize() with various types (dummy)
*/
TEST (ne_core_data_test, dummy_quantize) {
- data_type npu_types[] = {DATA_TYPE_SRNPU, DATA_TYPE_QASYMM8,
- DATA_TYPE_QSYMM16};
- data_type std_types[] = {
- DATA_TYPE_INT8, DATA_TYPE_UINT8, DATA_TYPE_INT16, DATA_TYPE_UINT16,
- DATA_TYPE_INT32, DATA_TYPE_UINT32, DATA_TYPE_INT64, DATA_TYPE_UINT64,
- DATA_TYPE_FLOAT32, DATA_TYPE_FLOAT64};
+ data_type npu_types[] = {DATA_TYPE_SRNPU, DATA_TYPE_QASYMM8, DATA_TYPE_QSYMM16};
+ data_type std_types[] = {DATA_TYPE_INT8, DATA_TYPE_UINT8, DATA_TYPE_INT16, DATA_TYPE_UINT16,
+ DATA_TYPE_INT32, DATA_TYPE_UINT32, DATA_TYPE_INT64, DATA_TYPE_UINT64,
+ DATA_TYPE_FLOAT32, DATA_TYPE_FLOAT64};
uint32_t data_dims[] = {1, 1, 1, 1024};
void *src_data = malloc (4096);
for (int w = 0; w < W; w++) {
for (int c = 0; c < C; c++) {
std_offset = c + C * (w + W * (h + n * H));
- npu_offset =
- c % MPA_L + MPA_L * (w + W * (h + (n + c / MPA_L) * H));
+ npu_offset = c % MPA_L + MPA_L * (w + W * (h + (n + c / MPA_L) * H));
EXPECT_EQ (src_data[std_offset], dst_data[npu_offset]);
}
}
for (int w = 0; w < W; w++) {
for (int c = 0; c < C; c++) {
std_offset = c + C * (w + W * (h + n * H));
- npu_offset =
- (c % MPA_L) + MPA_L * (w + W * (h + (n + c / MPA_L) * H));
+ npu_offset = (c % MPA_L) + MPA_L * (w + W * (h + (n + c / MPA_L) * H));
EXPECT_EQ (src_data[npu_offset], dst_data[std_offset]);
}
}
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
std_offset = w + W * (h + H * (c + n * C));
- npu_offset =
- (c % MPA_L) + MPA_L * (w + W * (h + (n + c / MPA_L) * H));
+ npu_offset = (c % MPA_L) + MPA_L * (w + W * (h + (n + c / MPA_L) * H));
EXPECT_EQ (src_data[std_offset], dst_data[npu_offset]);
}
}
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
std_offset = w + W * (h + H * (c + n * C));
- npu_offset =
- (c % MPA_L) + MPA_L * (w + W * (h + (n + c / MPA_L) * H));
+ npu_offset = (c % MPA_L) + MPA_L * (w + W * (h + (n + c / MPA_L) * H));
EXPECT_EQ (src_data[npu_offset], dst_data[std_offset]);
}
}
* @brief test Device's createInstance() with invalid types
*/
TEST (ne_core_handler_test, device_create_instance_invalid_n) {
- EXPECT_EQ (Device::createInstance (static_cast<dev_type> (0x1111), 0),
- nullptr);
- EXPECT_EQ (Device::createInstance (static_cast<dev_type> (0xFFFF), 0),
- nullptr);
+ EXPECT_EQ (Device::createInstance (static_cast<dev_type> (0x1111), 0), nullptr);
+ EXPECT_EQ (Device::createInstance (static_cast<dev_type> (0xFFFF), 0), nullptr);
}
/**
EXPECT_EQ (triv2->deallocMemory (0, 4096, addr), -EPERM);
EXPECT_EQ (triv2->stop (true), -EPERM);
EXPECT_EQ (triv2->setModel (&model_buf, &model), -EPERM);
- EXPECT_EQ (
- triv2->run (NPUINPUT_HOST, model, &input, nullptr, nullptr, nullptr),
- -EPERM);
+ EXPECT_EQ (triv2->run (NPUINPUT_HOST, model, &input, nullptr, nullptr, nullptr), -EPERM);
EXPECT_EQ (triv2->unsetModel (model), -EPERM);
}
* @brief test Device's alloc/deallocMemory ()
*/
TEST (ne_core_handler_test, device_memory) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
void *addr;
* @brief test Device's allocMemory () with error handling
*/
TEST (ne_core_handler_test, device_memory_args_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
void *addr;
* @brief test TRIV2's setModel ()
*/
TEST (ne_core_handler_test, triv2_set_model) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
generic_buffer model_buf = {0};
* @brief test TRIV2's setModel () with error handling
*/
TEST (ne_core_handler_test, triv2_set_model_invalid_args_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
generic_buffer model_buf = {0};
* @brief test TRIV2's setModel () with error handling
*/
TEST (ne_core_handler_test, triv2_set_model_invalid_data_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
generic_buffer model_buf = {0};
* @brief test TRIV2's unsetModel () with error handling
*/
TEST (ne_core_handler_test, triv2_unset_model_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
EXPECT_NE (device->unsetModel (nullptr), 0);
}
* @brief test Device's run ()
*/
TEST (ne_core_handler_test, triv2_run) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
/** prepare model */
user_cb_data data;
data.num_called = 0;
- EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data),
- 0);
- EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data),
- 0);
- EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data),
- 0);
+ EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data), 0);
+ EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data), 0);
+ EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data), 0);
wait_callbacks (data.num_called, max_called, data.m, data.cv);
EXPECT_EQ (data.num_called, max_called);
* @brief test TRIV2's run () with error handling
*/
TEST (ne_core_handler_test, triv2_run_invalid_args_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
/** TRIV2 requires valid model and buffer arguments */
* @brief test TRIV2's run () with error handling
*/
TEST (ne_core_handler_test, triv2_run_invalid_opmode_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
/** prepare model */
EXPECT_NE (device->run (NPUINPUT_INTERNAL_CAM, model, &input_buf), 0);
EXPECT_NE (device->run (NPUINPUT_I2S_MIC, model, &input_buf), 0);
EXPECT_NE (device->run (NPUINPUT_HW_RECURRING, model, &input_buf), 0);
- EXPECT_NE (
- device->run (static_cast<npu_input_opmode> (0x10), model, &input_buf), 0);
+ EXPECT_NE (device->run (static_cast<npu_input_opmode> (0x10), model, &input_buf), 0);
destroy_input_buffers (input_buf);
destroy_model_buffer (model_buf);
* @brief test Device's stop ()
*/
TEST (ne_core_handler_test, triv2_stop) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
/** prepare model */
user_cb_data data;
data.num_called = 0;
- EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data),
- 0);
- EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data),
- 0);
- EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data),
- 0);
- EXPECT_EQ (device->stop (false),
- 0); /* wait until all requests are resolved */
- usleep (TEST_SLEEP_MS); /** TODO remove this when stop() is implemented */
- EXPECT_EQ (data.num_called,
- max_called); /** callbacks are called successfully */
+ EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data), 0);
+ EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data), 0);
+ EXPECT_GT (device->run (opmode, model, &input_buf, nullptr, user_cb, &data), 0);
+ EXPECT_EQ (device->stop (false), 0); /* wait until all requests are resolved */
+ usleep (TEST_SLEEP_MS); /** TODO remove this when stop() is implemented */
+ EXPECT_EQ (data.num_called, max_called); /** callbacks are called successfully */
destroy_input_buffers (input_buf);
destroy_model_buffer (model_buf);
* @brief test HostHandler's registerModel ()
*/
TEST (ne_core_handler_test, handler_register_model) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's registerModel () with error handling
*/
TEST (ne_core_handler_test, handler_register_model_invalid_args_01_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's registerModel () with error handling
*/
TEST (ne_core_handler_test, handler_register_model_invalid_args_02_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's unregisterModel () with error handling
*/
TEST (ne_core_handler_test, handler_unregister_model_invalid_id_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's getModel () with error handling
*/
TEST (ne_core_handler_test, handler_get_model_invalid_id_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's setDataInfo ()
*/
TEST (ne_core_handler_test, handler_set_data_info) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's setDataInfo () with error handling
*/
TEST (ne_core_handler_test, handler_set_data_info_invalid_args_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's setConstraint ()
*/
TEST (ne_core_handler_test, handler_set_constraint) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's setConstraint () with error handling
*/
TEST (ne_core_handler_test, handler_set_constraint_invalid_args_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's allocGenericBuffer ()
*/
TEST (ne_core_handler_test, handler_generic_buffer) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's allocGenericBuffer () with error handling
*/
TEST (ne_core_handler_test, handler_generic_buffer_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
ASSERT_NE (handler, nullptr);
/** invalid args */
- EXPECT_NE (
- handler->allocGenericBuffer (static_cast<generic_buffer *> (nullptr)), 0);
- EXPECT_NE (
- handler->deallocGenericBuffer (static_cast<generic_buffer *> (nullptr)),
- 0);
+ EXPECT_NE (handler->allocGenericBuffer (static_cast<generic_buffer *> (nullptr)), 0);
+ EXPECT_NE (handler->deallocGenericBuffer (static_cast<generic_buffer *> (nullptr)), 0);
/** invalid type */
generic_buffer buf = {0};
* @brief test HostHandler's allocGenericBuffer () with error handling
*/
TEST (ne_core_handler_test, handler_generic_buffers_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
ASSERT_NE (handler, nullptr);
/** invalid args */
- EXPECT_NE (
- handler->allocGenericBuffer (static_cast<generic_buffers *> (nullptr)),
- 0);
- EXPECT_NE (
- handler->deallocGenericBuffer (static_cast<generic_buffers *> (nullptr)),
- 0);
+ EXPECT_NE (handler->allocGenericBuffer (static_cast<generic_buffers *> (nullptr)), 0);
+ EXPECT_NE (handler->deallocGenericBuffer (static_cast<generic_buffers *> (nullptr)), 0);
/** invalid type */
* @brief test HostHandler's runModel (sync)
*/
TEST (ne_core_handler_test, handler_triv2_run_sync) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's runModel (sync) with error handling
*/
TEST (ne_core_handler_test, handler_triv2_run_model_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's runModel (async)
*/
TEST (ne_core_handler_test, handler_triv2_run_async) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's runModel (async) with error handling
*/
TEST (ne_core_handler_test, handler_triv2_run_async_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
TEST (ne_core_handler_test, handler_triv2_get_memory_status) {
// disabled until this feature is implemented
#if defined(ENABLE_EMUL)
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test HostHandler's getMemoryStatus () with error handling
*/
TEST (ne_core_handler_test, handler_triv2_get_memory_status_n) {
- std::unique_ptr<Device> device (
- Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
+ std::unique_ptr<Device> device (Device::createInstance (NPUCOND_TRIV2_CONN_SOCIP, 0));
ASSERT_NE (device.get (), nullptr);
HostHandler *handler = device->getHostHandler ();
* @brief test primitives of memory allocator default (MemDefault)
*/
TEST (ne_core_mem_test, mem_default_primitives) {
- std::unique_ptr<DriverAPI> api =
- DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
+ std::unique_ptr<DriverAPI> api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get (), nullptr);
/**
* @brief test primitives of memory allocator (unimplemented)
*/
TEST (ne_core_mem_test, mem_pool_primitives_n) {
- std::unique_ptr<DriverAPI> api =
- DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
+ std::unique_ptr<DriverAPI> api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
ASSERT_NE (api.get (), nullptr);
/** 'resv_mem_size' > 0: MemPool (not implemented yet) */
EXPECT_EQ (model->setMetadata (&data), 0);
EXPECT_NE (model->getMetadata (), nullptr);
- EXPECT_EQ (model->getInputTensorNum (),
- exp_num_tensors_v1); /* v1 has one input/output tensors */
+ EXPECT_EQ (model->getInputTensorNum (), exp_num_tensors_v1); /* v1 has one input/output tensors */
EXPECT_EQ (model->getOutputTensorNum (), exp_num_tensors_v1);
EXPECT_EQ (model->getInputTensorSize (0), exp_size_input);
EXPECT_EQ (meta->getInputOffset (0), data.input_offset);
EXPECT_EQ (meta->getInputTensorSize (0, DATA_LAYOUT_SRNPU), data.input_size);
EXPECT_EQ (meta->getOutputOffset (0), data.output_offset);
- EXPECT_EQ (meta->getOutputTensorSize (0, DATA_LAYOUT_SRNPU),
- data.output_size);
+ EXPECT_EQ (meta->getOutputTensorSize (0, DATA_LAYOUT_SRNPU), data.output_size);
/** return default values for unsupported info */
EXPECT_EQ (meta->getInputElemSize (0), (uint32_t) 1);
EXPECT_EQ (meta->getOutputElemSize (0), (uint32_t) 1);
- EXPECT_EQ (meta->getInputDims (0)[0],
- meta->getInputTensorSize (0, default_data_layout));
- EXPECT_EQ (meta->getOutputDims (0)[0],
- meta->getOutputTensorSize (0, default_data_layout));
+ EXPECT_EQ (meta->getInputDims (0)[0], meta->getInputTensorSize (0, default_data_layout));
+ EXPECT_EQ (meta->getOutputDims (0)[0], meta->getOutputTensorSize (0, default_data_layout));
EXPECT_EQ (meta->getInputQuantZero (0), default_quant_zero);
EXPECT_EQ (meta->getOutputQuantZero (0), default_quant_zero);
EXPECT_FLOAT_EQ (meta->getInputQuantScale (0), default_quant_scale);
for (uint32_t i = 0; i < data.output_num; i++) {
data.output_offsets[i] = 100 * (i + 1);
data.output_elem_size[i] = 1 * (i + 1);
- for (uint32_t j = 0; j < MAX_RANK; j++)
- data.output_dims[i][j] = 2 * (i + 1);
+ for (uint32_t j = 0; j < MAX_RANK; j++) data.output_dims[i][j] = 2 * (i + 1);
data.output_quant_z[i] = 3 * (i + 1);
data.output_quant_s[i] = 4 * (i + 1);
}
for (uint32_t i = 0; i < meta->getInputNum (); i++) {
EXPECT_EQ (meta->getInputOffset (i), 100 * (i + 1));
EXPECT_EQ (meta->getInputElemSize (i), 1 * (i + 1));
- for (uint32_t j = 0; j < MAX_RANK; j++)
- EXPECT_EQ (meta->getInputDims (i)[j], 2 * (i + 1));
+ for (uint32_t j = 0; j < MAX_RANK; j++) EXPECT_EQ (meta->getInputDims (i)[j], 2 * (i + 1));
EXPECT_EQ (meta->getInputQuantZero (i), 3 * (i + 1));
EXPECT_EQ (meta->getInputQuantScale (i), 4 * (i + 1));
}
for (uint32_t i = 0; i < meta->getOutputNum (); i++) {
EXPECT_EQ (meta->getOutputOffset (i), 100 * (i + 1));
EXPECT_EQ (meta->getOutputElemSize (i), 1 * (i + 1));
- for (uint32_t j = 0; j < MAX_RANK; j++)
- EXPECT_EQ (meta->getOutputDims (i)[j], 2 * (i + 1));
+ for (uint32_t j = 0; j < MAX_RANK; j++) EXPECT_EQ (meta->getOutputDims (i)[j], 2 * (i + 1));
EXPECT_EQ (meta->getOutputQuantZero (i), 3 * (i + 1));
EXPECT_EQ (meta->getOutputQuantScale (i), 4 * (i + 1));
}
data.input_seg_num = input_num;
for (uint32_t i = 0; i < data.input_seg_num; i++) {
data.input_seg_idx[i] = i;
- for (uint32_t j = 0; j < MAX_RANK; j++)
- data.input_seg_dims[i][j] = 2 * (i + 1);
+ for (uint32_t j = 0; j < MAX_RANK; j++) data.input_seg_dims[i][j] = 2 * (i + 1);
data.input_seg_quant_z[i] = 3 * (i + 1);
data.input_seg_quant_s[i] = 4 * (i + 1);
data.input_seg_quant_type[i] = DATA_TYPE_QASYMM8;
data.output_seg_num = output_num;
for (uint32_t i = 0; i < data.output_seg_num; i++) {
data.output_seg_idx[i] = data.input_seg_num + i;
- for (uint32_t j = 0; j < MAX_RANK; j++)
- data.output_seg_dims[i][j] = 2 * (i + 1);
+ for (uint32_t j = 0; j < MAX_RANK; j++) data.output_seg_dims[i][j] = 2 * (i + 1);
data.output_seg_quant_z[i] = 3 * (i + 1);
data.output_seg_quant_s[i] = 4 * (i + 1);
data.output_seg_quant_type[i] = DATA_TYPE_QSYMM16;
const uint32_t exp_num_threads = 16;
const size_t exp_rsv_mem_sizeg = 1;
const size_t exp_rsv_mem_sizeb = exp_rsv_mem_sizeg * 1024 * 1024 * 1024;
- const std::string exp_str_rsv_mem_sizeg (std::to_string (exp_rsv_mem_sizeg) +
- "G");
+ const std::string exp_str_rsv_mem_sizeg (std::to_string (exp_rsv_mem_sizeg) + "G");
const std::string exp_str_num_threads (std::to_string (exp_num_threads));
ENV_PAIR envvars;
save_and_unset_envvars (envvars);
Logger &logger = Logger::getInstance ();
int ret;
- ret = logger.logwrite (NPU_LOG_ERROR, _N1,
- "testing log severity level (error)\n");
+ ret = logger.logwrite (NPU_LOG_ERROR, _N1, "testing log severity level (error)\n");
EXPECT_GE (ret, 0);
- ret = logger.logwrite (NPU_LOG_WARN, _N1,
- "testing log severity level (warn)\n");
+ ret = logger.logwrite (NPU_LOG_WARN, _N1, "testing log severity level (warn)\n");
EXPECT_GE (ret, 0);
- ret = logger.logwrite (NPU_LOG_INFO, _N1,
- "testing log severity level (info)\n");
+ ret = logger.logwrite (NPU_LOG_INFO, _N1, "testing log severity level (info)\n");
EXPECT_GE (ret, 0);
}
extra = (uint8_t *) malloc (extra_size * NPUBIN_META_SIZE);
memset (extra, 0, extra_size * NPUBIN_META_SIZE);
- cnt =
- fwrite (extra, extra_size * (NPUBIN_META_SIZE / 2), 1, meta_only_bin_fp);
+ cnt = fwrite (extra, extra_size * (NPUBIN_META_SIZE / 2), 1, meta_only_bin_fp);
fclose (meta_only_bin_fp);
free (extra);
if (cnt != 1)
/* actual testing (blocking) */
int req_id;
EXPECT_EQ (createNPU_request (dev, modelid, &req_id), 0);
- EXPECT_EQ (
- setNPU_requestData (dev, req_id, &input, &info_in, &output, &info_out),
- 0);
+ EXPECT_EQ (setNPU_requestData (dev, req_id, &input, &info_in, &output, &info_out), 0);
EXPECT_EQ (setNPU_requestMode (dev, req_id, NPU_INFER_BLOCKING), 0);
EXPECT_EQ (setNPU_requestConstraint (dev, req_id, constraint), 0);
sync.done = false;
EXPECT_EQ (createNPU_request (dev, modelid, &req_id), 0);
- EXPECT_EQ (
- setNPU_requestData (dev, req_id, &input, &info_in, &output, &info_out),
- 0);
+ EXPECT_EQ (setNPU_requestData (dev, req_id, &input, &info_in, &output, &info_out), 0);
EXPECT_EQ (setNPU_requestMode (dev, req_id, NPU_INFER_NON_BLOCKING), 0);
EXPECT_EQ (setNPU_requestCallback (dev, req_id, test_callback, &sync), 0);
EXPECT_EQ (setNPU_requestConstraint (dev, req_id, constraint), 0);
int req_ids[max_iters];
/* nobody will invoke the requests */
- for (int i = 0; i < max_iters; i++) {
+ for (uint32_t i = 0; i < max_iters; i++) {
EXPECT_EQ (createNPU_request (dev, modelid, &req_ids[i]), 0);
/* regardless of setting which scheduler, kernel requests will use the VD scheculder */
if ((i % 3) == 1) {
- EXPECT_EQ (
- setNPU_requestScheduler (dev, req_ids[i], NPU_SCHEDULER_SR, nullptr),
- 0);
+ EXPECT_EQ (setNPU_requestScheduler (dev, req_ids[i], NPU_SCHEDULER_SR, nullptr), 0);
} else if ((i % 3) == 2) {
- EXPECT_EQ (
- setNPU_requestScheduler (dev, req_ids[i], NPU_SCHEDULER_VD, nullptr),
- 0);
+ EXPECT_EQ (setNPU_requestScheduler (dev, req_ids[i], NPU_SCHEDULER_VD, nullptr), 0);
}
EXPECT_EQ (setNPU_requestConstraint (dev, req_ids[i], constraint), 0);
EXPECT_EQ (submitNPU_requestKernel (dev, req_ids[i]), 0);
sleep (1);
- for (int i = 0; i < max_iters; i++)
- EXPECT_EQ (removeNPU_request (dev, req_ids[i]), 0);
+ for (uint32_t i = 0; i < max_iters; i++) EXPECT_EQ (removeNPU_request (dev, req_ids[i]), 0);
ASSERT_EQ (unregisterNPUmodel (dev, modelid), 0);
putNPUdevice (dev);
NPU_LOG_INFO,
};
- for (auto &level : levels)
- EXPECT_EQ (writeNPU_log (level, "TEST", "testing logs..."), 0);
+ for (auto &level : levels) EXPECT_EQ (writeNPU_log (level, "TEST", "testing logs..."), 0);
}
/**
case BUFFER_DMABUF:
/* BUFFER_MAPPED, BUFFER_DMABUF */
memcpy (buffer->addr, meta, NPUBIN_META_SIZE);
- fill_program ((char *) buffer->addr + NPUBIN_META_SIZE,
- meta->program_size);
- fill_weight (
- (char *) buffer->addr + NPUBIN_META_SIZE + meta->program_size,
- meta->weight_size);
+ fill_program ((char *) buffer->addr + NPUBIN_META_SIZE, meta->program_size);
+ fill_weight ((char *) buffer->addr + NPUBIN_META_SIZE + meta->program_size,
+ meta->weight_size);
break;
default:
break;
closedir (d);
putNPUdevice (dev);
- fprintf (stderr, "[APPTEST] %s: PASSED (%d), FAILED (%d), SKIPPED (%d)\n",
- name, total_succs, total_fails, total_skpds);
+ fprintf (stderr, "[APPTEST] %s: PASSED (%d), FAILED (%d), SKIPPED (%d)\n", name, total_succs,
+ total_fails, total_skpds);
return -total_fails;
}
goto recheck;
}
- fprintf (stderr, "memory leak check failed (0x%zx != 0x%zx)\n", free_total,
- alloc_total);
+ fprintf (stderr, "memory leak check failed (0x%zx != 0x%zx)\n", free_total, alloc_total);
return -EINVAL;
}
}
/** @brief parse/set arguments and get working directory */
int
-UtilTrinity::parseArgs (int argc, char **argv, const char *param_str,
- int *index) {
+UtilTrinity::parseArgs (int argc, char **argv, const char *param_str, int *index) {
int c;
if (index != nullptr)
/** @brief load NPU model and set relevant info */
int
-UtilTrinity::loadModel (std::string dirpath, uint32_t *model_id_ptr,
- npu_priority priority, uint32_t timeout) {
+UtilTrinity::loadModel (std::string dirpath, uint32_t *model_id_ptr, npu_priority priority,
+ uint32_t timeout) {
if (dirpath == "")
return -EINVAL;
UtilModel *model = static_cast<UtilModel *> (data);
if (model == nullptr) {
- for (uint32_t idx = 0; idx < output->num_buffers; idx++)
- free (output->bufs[idx].addr);
+ for (uint32_t idx = 0; idx < output->num_buffers; idx++) free (output->bufs[idx].addr);
}
std::unique_lock<std::mutex> lock (m_);
if (model) {
cb_output = model->getOutput ();
- status =
- runNPU_model (dev_, model->getModelID (), NPU_INFER_BLOCKING,
- model->getInput (), model->getOutput (), NULL, NULL);
+ status = runNPU_model (dev_, model->getModelID (), NPU_INFER_BLOCKING, model->getInput (),
+ model->getOutput (), NULL, NULL);
} else {
/* TODO: revise this when TRIA is implemented */
input_buffers input;
}
} else {
if (model) {
- status =
- runNPU_model (dev_, model->getModelID (), NPU_INFER_NON_BLOCKING,
- model->getInput (), model->getOutput (), cb, cb_data);
+ status = runNPU_model (dev_, model->getModelID (), NPU_INFER_NON_BLOCKING, model->getInput (),
+ model->getOutput (), cb, cb_data);
} else {
/* TODO: revise this when TRIA is implemented */
input_buffers input;
if (status != 0)
return status;
- status = setNPU_requestData (dev_, req_id, model->getInput (), nullptr,
- model->getOutput (), nullptr);
+ status =
+ setNPU_requestData (dev_, req_id, model->getInput (), nullptr, model->getOutput (), nullptr);
if (status != 0) {
removeNPU_request (dev_, req_id);
return status;
status = submitNPU_request (dev_, req_id);
if (status == 0) {
total_++;
- UtilTrinity::callbackVerify (model->getOutput (), req_id,
- static_cast<void *> (model));
+ UtilTrinity::callbackVerify (model->getOutput (), req_id, static_cast<void *> (model));
}
return status;
/** @brief configure constraint for the model */
int
-UtilTrinity::set_constraint (uint32_t model_id, uint32_t timeout,
- npu_priority priority) {
+UtilTrinity::set_constraint (uint32_t model_id, uint32_t timeout, npu_priority priority) {
npuConstraint constraint;
constraint.timeout_ms = timeout;
} else {
inpath_.resize (num);
for (uint32_t idx = 0; idx < num; idx++)
- inpath_[idx] =
- dirpath_ + "/input_fmap_" + std::to_string (idx) + ".bin";
+ inpath_[idx] = dirpath_ + "/input_fmap_" + std::to_string (idx) + ".bin";
}
}
void prepareOutputPath (uint32_t num) {
} else {
outpath_.resize (num);
for (uint32_t idx = 0; idx < num; idx++)
- outpath_[idx] =
- dirpath_ + "/output_fmap_" + std::to_string (idx) + ".bin";
+ outpath_[idx] = dirpath_ + "/output_fmap_" + std::to_string (idx) + ".bin";
}
}
const char *getInputPath (uint32_t idx) { return inpath_[idx].c_str (); }
int init (uint32_t tops = default_tops);
void clear ();
void printUsage (const char *prog_name, const char *param_str = nullptr);
- int parseArgs (int argc, char **argv, const char *param_str = nullptr,
- int *index = nullptr);
- int loadModel (std::string dirpath, uint32_t *model_id,
- npu_priority priority = NPU_PRIORITY_MID,
+ int parseArgs (int argc, char **argv, const char *param_str = nullptr, int *index = nullptr);
+ int loadModel (std::string dirpath, uint32_t *model_id, npu_priority priority = NPU_PRIORITY_MID,
uint32_t timeout = 5000);
int unloadModel (uint32_t model_id);
std::string node_;
private:
- int set_constraint (uint32_t model_id, uint32_t timeout,
- npu_priority priority);
+ int set_constraint (uint32_t model_id, uint32_t timeout, npu_priority priority);
int run_each (UtilModel *model, bool sync);
virtual bool check_version (npubin_meta *meta) { return false; }
virtual int prepare_model (UtilModel *model) { return -EPERM; }
- virtual int set_data_info (npubin_meta *meta, uint32_t model_id) {
- return -EPERM;
- }
+ virtual int set_data_info (npubin_meta *meta, uint32_t model_id) { return -EPERM; }
virtual bool extract_node_id (uint32_t *id) { return false; }
dev_type type_;
* @param[in] buf_type The memory type of the buffer included in the model
* @return A generic buffer including dummy model data, NULL if error
*/
-generic_buffer *make_model (npudev_h dev, npubin_meta *meta,
- buffer_types buf_type);
+generic_buffer *make_model (npudev_h dev, npubin_meta *meta, buffer_types buf_type);
/**
* @brief Destroy generic buffer with model data
* @return 0 if no error, otherwise a negative errno
*/
int
-compare_data (const char *golden_path, const char *output_data,
- uint64_t output_size) {
+compare_data (const char *golden_path, const char *output_data, uint64_t output_size) {
ifstream ifs (golden_path, ios::binary | ios::ate);
if (!ifs.good ()) {
cerr << "Unable to find the file " << golden_path << "\n";
/* find the first mismatch */
int err = 0;
- auto mispair =
- mismatch (golden_vec.begin (), golden_vec.end (), output_vec.begin ());
+ auto mispair = mismatch (golden_vec.begin (), golden_vec.end (), output_vec.begin ());
if (mispair.first != golden_vec.end ()) {
uint32_t idx = distance (golden_vec.begin (), mispair.first);
}
static inline void
-test_callback_sleep (int *num_called, std::mutex *m,
- std::condition_variable *cv) {
+test_callback_sleep (int *num_called, std::mutex *m, std::condition_variable *cv) {
{
std::unique_lock<std::mutex> lock (*m);
(*num_called)++;
}
static inline void
-wait_callbacks (int &num_called, int max_called, std::mutex &m,
- std::condition_variable &cv) {
+wait_callbacks (int &num_called, int max_called, std::mutex &m, std::condition_variable &cv) {
std::unique_lock<std::mutex> lock (m);
cv.wait (lock, [&]() { return max_called == num_called; });
}
* @param[in] output_size the output data size
* @return 0 if no error, otherwise a negative errno
*/
-int compare_data (const char *golden_path, const char *output_data,
- uint64_t output_size);
+int compare_data (const char *golden_path, const char *output_data, uint64_t output_size);
#if defined(__cplusplus)
}
try {
testing::InitGoogleTest (&argc, argv);
} catch (...) {
- std::cerr << "catch 'testing::internal::<unnamed>::ClassUniqueToAlwaysTrue'"
- << std::endl;
+ std::cerr << "catch 'testing::internal::<unnamed>::ClassUniqueToAlwaysTrue'" << std::endl;
}
try {
ret = RUN_ALL_TESTS ();
} catch (...) {
- std::cerr << "catch `testing::internal::GoogleTestFailureException`"
- << std::endl;
+ std::cerr << "catch `testing::internal::GoogleTestFailureException`" << std::endl;
}
return ret;
}
}
std::cout << "\n";
std::cout << " weight_seg_idx: ";
- std::cout << (meta_->weight_seg_idx < meta_->segment_num
- ? std::to_string (meta_->weight_seg_idx)
- : "N/A");
+ std::cout << (meta_->weight_seg_idx < meta_->segment_num ? std::to_string (meta_->weight_seg_idx)
+ : "N/A");
std::cout << "\n\n";
std::cout << " input_seg_num: " << meta_->input_seg_num << "\n";
for (uint32_t i = 0; i < meta_->input_seg_num; i++) {
/* create a shared memory */
mode_t old_umask = umask (0);
- shm_name_ =
- "/triv2_" + std::to_string (app_id) + "_" + std::to_string (fd_);
+ shm_name_ = "/triv2_" + std::to_string (app_id) + "_" + std::to_string (fd_);
shm_fd_ = shm_open (shm_name_.c_str (), O_RDWR | O_CREAT, 0666);
umask (old_umask);
}
if (l.deleted_ || r.deleted_)
return false;
- if ((l.dbuf_fd_ != r.dbuf_fd_) ||
- (l.program_offset_addr_ != r.program_offset_addr_) ||
+ if ((l.dbuf_fd_ != r.dbuf_fd_) || (l.program_offset_addr_ != r.program_offset_addr_) ||
(l.program_size_ != r.program_size_) || (l.version_ != r.version_))
return false;
int64_t getInputFootprint () const { return profile_.dram_input_footprint; }
int64_t getOutputFootprint () const { return profile_.dram_output_footprint; }
void *getData () const { return profile_.layers; }
- size_t getDataSize () const {
- return profile_.num_layers * sizeof (npu_profile_layer);
- }
+ size_t getDataSize () const { return profile_.num_layers * sizeof (npu_profile_layer); }
bool parse () {
std::ifstream ifs (prof_path_, std::ios::binary);
profile_.prof_path = strdup (prof_path_.c_str ());
if (!profile_.prof_path) {
- std::cerr << "Unable to duplicate the profile path " << prof_path_
- << "\n";
+ std::cerr << "Unable to duplicate the profile path " << prof_path_ << "\n";
return false;
}
if (head.fmt_vesion != TRIV2PROF_FMT_VER) {
std::cerr << "Profile data format mismatch: "
- << "(" << head.fmt_vesion << " vs. " << TRIV2PROF_FMT_VER
- << ")\n";
+ << "(" << head.fmt_vesion << " vs. " << TRIV2PROF_FMT_VER << ")\n";
return false;
}
ifs.read ((char *) &nna_dma, sizeof (T2PF_DUMP_DMA));
snprintf (layer->name, NPU_OPNAME_MAX, "%s", "ADMA_IN");
- layer->dram_read_bytes =
- nna_dma.src_addr_end - nna_dma.src_addr_start;
- layer->sram_write_bytes =
- nna_dma.dest_addr_end - nna_dma.dest_addr_start;
+ layer->dram_read_bytes = nna_dma.src_addr_end - nna_dma.src_addr_start;
+ layer->sram_write_bytes = nna_dma.dest_addr_end - nna_dma.dest_addr_start;
break;
case TRIV2PROF_BLOCKID_NNA_DMA_OUT:
ifs.read ((char *) &nna_dma, sizeof (T2PF_DUMP_DMA));
snprintf (layer->name, NPU_OPNAME_MAX, "%s", "ADMA_OUT");
- layer->dram_write_bytes =
- nna_dma.dest_addr_end - nna_dma.dest_addr_start;
- layer->sram_read_bytes =
- nna_dma.src_addr_end - nna_dma.src_addr_start;
+ layer->dram_write_bytes = nna_dma.dest_addr_end - nna_dma.dest_addr_start;
+ layer->sram_read_bytes = nna_dma.src_addr_end - nna_dma.src_addr_start;
break;
case TRIV2PROF_BLOCKID_DSP:
ifs.read ((char *) &dsp, sizeof (T2PF_DUMP_DSP));
ifs.read ((char *) &dsp_dma, sizeof (T2PF_DUMP_DMA));
snprintf (layer->name, NPU_OPNAME_MAX, "%s", "PDMA_IN");
- layer->dram_read_bytes =
- dsp_dma.src_addr_end - dsp_dma.src_addr_start;
- layer->sram_write_bytes =
- dsp_dma.dest_addr_end - dsp_dma.dest_addr_start;
+ layer->dram_read_bytes = dsp_dma.src_addr_end - dsp_dma.src_addr_start;
+ layer->sram_write_bytes = dsp_dma.dest_addr_end - dsp_dma.dest_addr_start;
break;
case TRIV2PROF_BLOCKID_DSP_DMA_OUT:
ifs.read ((char *) &dsp_dma, sizeof (T2PF_DUMP_DMA));
snprintf (layer->name, NPU_OPNAME_MAX, "%s", "PDMA_OUT");
- layer->dram_write_bytes =
- dsp_dma.dest_addr_end - dsp_dma.dest_addr_start;
- layer->sram_read_bytes =
- dsp_dma.src_addr_end - dsp_dma.src_addr_start;
+ layer->dram_write_bytes = dsp_dma.dest_addr_end - dsp_dma.dest_addr_start;
+ layer->sram_read_bytes = dsp_dma.src_addr_end - dsp_dma.src_addr_start;
break;
default:
- std::cerr << "Unknown block id detected: " << common.block_id
- << std::endl;
+ std::cerr << "Unknown block id detected: " << common.block_id << std::endl;
delete[] profile_.layers;
profile_.layers = nullptr;
ifs.close ();
class EmulStatReq {
public:
- EmulStatReq (const trinity_cuse_stat_req &stat)
- : stat_ (stat), profile_ (nullptr) {}
+ EmulStatReq (const trinity_cuse_stat_req &stat) : stat_ (stat), profile_ (nullptr) {}
~EmulStatReq () {
if (profile_)
global_profile_map.remove (stat_.req_id);
* @brief TRIV2 impl. of hwmem_dealloc ioctl()
*/
static int
-triv2_hwmem_dealloc (trinity_cuse_context *ctx,
- const trinity_cuse_hwmem *hwmem) {
+triv2_hwmem_dealloc (trinity_cuse_context *ctx, const trinity_cuse_hwmem *hwmem) {
EmulDmabuf *dmabuf = global_dmabuf_map.find (hwmem->dbuf_fd);
if (dmabuf == nullptr)
return -ENOENT;
* @brief TRIV2 impl. of run_input ioctl()
*/
static int
-triv2_run_input (trinity_cuse_context *ctx, const trinity_cuse_input *in,
- trinity_cuse_input *out) {
+triv2_run_input (trinity_cuse_context *ctx, const trinity_cuse_input *in, trinity_cuse_input *out) {
EmulDmabuf *dbuf_input = global_dmabuf_map.find (in->dbuf_fd);
if (dbuf_input == nullptr)
return -ENOENT;
for (uint32_t i = 0; i < num_segs; i++) {
int dbuf_fd = reinterpret_cast<int *> (input)[i];
- uint32_t offset =
- reinterpret_cast<uint32_t *> ((char *) input + PAGE_SIZE / 2)[i];
+ uint32_t offset = reinterpret_cast<uint32_t *> ((char *) input + PAGE_SIZE / 2)[i];
EmulDmabuf *dbuf_seg = global_dmabuf_map.find (dbuf_fd);
if (dbuf_seg == nullptr) {
EmulStatReq *stat_req = stat->createReqStat (stat_req_data);
- std::chrono::steady_clock::time_point begin =
- std::chrono::steady_clock::now ();
+ std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now ();
run_triv2_emul (prog, segt, meta, cmd_path.c_str (), prof_path.c_str ());
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now ();
stat_req->updateInferTime (
- std::chrono::duration_cast<std::chrono::milliseconds> (end - begin)
- .count ());
+ std::chrono::duration_cast<std::chrono::milliseconds> (end - begin).count ());
EmulProfile *profile = new EmulProfile (req_id, prof_path + ".rec");
stat_req->setProfile (profile);
* @brief TRIV2 impl. of stat_current_app ioctl()
*/
static int
-triv2_stat_current_app (trinity_cuse_context *ctx,
- trinity_cuse_stat_app *stat) {
+triv2_stat_current_app (trinity_cuse_context *ctx, trinity_cuse_stat_app *stat) {
EmulStat *s = global_stat_map.find (ctx->app_id);
if (s == nullptr)
return -ENOENT;
std::function<bool(EmulStat *)> functor = [&](EmulStat *s) -> bool {
if (stat->num_apps < TRINITY_APP_STAT_MAX) {
- memcpy (&stat->stat[stat->num_apps++], s->getStatApp (),
- sizeof (trinity_cuse_stat_app));
+ memcpy (&stat->stat[stat->num_apps++], s->getStatApp (), sizeof (trinity_cuse_stat_app));
}
/* don't remove */
return false;
* @brief TRIV2 impl. of get_profile_meta ioctl()
*/
static int
-triv2_get_profile_meta (trinity_cuse_context *ctx,
- const trinity_cuse_profile_meta *in,
+triv2_get_profile_meta (trinity_cuse_context *ctx, const trinity_cuse_profile_meta *in,
trinity_cuse_profile_meta *out) {
EmulProfile *profile = global_profile_map.find (in->req_id);
if (profile == nullptr)
* @brief TRIV2 impl. of get_profile_buff ioctl()
*/
static int
-triv2_get_profile_buff (trinity_cuse_context *ctx,
- const trinity_cuse_profile_buff *in,
+triv2_get_profile_buff (trinity_cuse_context *ctx, const trinity_cuse_profile_buff *in,
trinity_cuse_profile_buff *out, void *data) {
EmulProfile *profile = global_profile_map.find (in->req_id);
if (profile == nullptr)
return -ERANGE;
*out = *in;
- memcpy (data, (char *) profile->getData () + in->profile_pos,
- in->profile_size);
+ memcpy (data, (char *) profile->getData () + in->profile_pos, in->profile_size);
return 0;
}
* @brief impl. of .ioctl ()
*/
static void
-trinity_cuse_ioctl (fuse_req_t req, int cmd, void *arg,
- struct fuse_file_info *fi, unsigned int flags,
- const void *in_buf, size_t in_size, size_t out_size) {
+trinity_cuse_ioctl (fuse_req_t req, int cmd, void *arg, struct fuse_file_info *fi,
+ unsigned int flags, const void *in_buf, size_t in_size, size_t out_size) {
trinity_cuse_context *ctx = (trinity_cuse_context *) fi->fh;
if (flags & FUSE_IOCTL_COMPAT) {
struct iovec iov = {arg, sizeof (trinity_cuse_hwmem)};
fuse_reply_ioctl_retry (req, &iov, 1, NULL, 0);
} else {
- const trinity_cuse_hwmem *val =
- static_cast<const trinity_cuse_hwmem *> (in_buf);
+ const trinity_cuse_hwmem *val = static_cast<const trinity_cuse_hwmem *> (in_buf);
fuse_reply_ioctl (req, vtable->hwmem_alloc (ctx, val), NULL, 0);
}
break;
struct iovec iov = {arg, sizeof (trinity_cuse_hwmem)};
fuse_reply_ioctl_retry (req, &iov, 1, NULL, 0);
} else {
- const trinity_cuse_hwmem *val =
- static_cast<const trinity_cuse_hwmem *> (in_buf);
+ const trinity_cuse_hwmem *val = static_cast<const trinity_cuse_hwmem *> (in_buf);
fuse_reply_ioctl (req, vtable->hwmem_dealloc (ctx, val), NULL, 0);
}
break;
struct iovec iov = {arg, sizeof (trinity_cuse_model)};
fuse_reply_ioctl_retry (req, &iov, 1, &iov, 1);
} else {
- const trinity_cuse_model *in_val =
- static_cast<const trinity_cuse_model *> (in_buf);
+ const trinity_cuse_model *in_val = static_cast<const trinity_cuse_model *> (in_buf);
trinity_cuse_model out_val;
- fuse_reply_ioctl (req, vtable->register_model (ctx, in_val, &out_val),
- &out_val, sizeof (out_val));
+ fuse_reply_ioctl (req, vtable->register_model (ctx, in_val, &out_val), &out_val,
+ sizeof (out_val));
}
break;
case TRINITY_IOCTL_DEREGISTER_MODEL:
struct iovec iov = {arg, sizeof (trinity_cuse_input)};
fuse_reply_ioctl_retry (req, &iov, 1, &iov, 1);
} else {
- const trinity_cuse_input *in_val =
- static_cast<const trinity_cuse_input *> (in_buf);
+ const trinity_cuse_input *in_val = static_cast<const trinity_cuse_input *> (in_buf);
trinity_cuse_input out_val;
- fuse_reply_ioctl (req, vtable->run_input (ctx, in_val, &out_val),
- &out_val, sizeof (out_val));
+ fuse_reply_ioctl (req, vtable->run_input (ctx, in_val, &out_val), &out_val,
+ sizeof (out_val));
}
break;
case TRINITY_IOCTL_STOP_REQUESTS:
fuse_reply_ioctl_retry (req, NULL, 0, &iov, 1);
} else {
trinity_cuse_stat_app val;
- fuse_reply_ioctl (req, vtable->stat_current_app (ctx, &val), &val,
- sizeof (val));
+ fuse_reply_ioctl (req, vtable->stat_current_app (ctx, &val), &val, sizeof (val));
}
break;
case TRINITY_IOCTL_STAT_APPS:
fuse_reply_ioctl_retry (req, NULL, 0, &iov, 1);
} else {
trinity_cuse_stat_apps val;
- fuse_reply_ioctl (req, vtable->stat_apps (ctx, &val), &val,
- sizeof (val));
+ fuse_reply_ioctl (req, vtable->stat_apps (ctx, &val), &val, sizeof (val));
}
break;
case TRINITY_IOCTL_STAT_REQS:
struct iovec iov = {arg, sizeof (trinity_cuse_stat_reqs)};
fuse_reply_ioctl_retry (req, &iov, 1, &iov, 1);
} else {
- const trinity_cuse_stat_reqs *in_val =
- static_cast<const trinity_cuse_stat_reqs *> (in_buf);
+ const trinity_cuse_stat_reqs *in_val = static_cast<const trinity_cuse_stat_reqs *> (in_buf);
trinity_cuse_stat_reqs out_val;
- fuse_reply_ioctl (req, vtable->stat_reqs (ctx, in_val, &out_val),
- &out_val, sizeof (out_val));
+ fuse_reply_ioctl (req, vtable->stat_reqs (ctx, in_val, &out_val), &out_val,
+ sizeof (out_val));
}
break;
case TRINITY_IOCTL_GET_PROFILE_META:
const trinity_cuse_profile_meta *in_val =
static_cast<const trinity_cuse_profile_meta *> (in_buf);
trinity_cuse_profile_meta out_val;
- fuse_reply_ioctl (req, vtable->get_profile_meta (ctx, in_val, &out_val),
- &out_val, sizeof (out_val));
+ fuse_reply_ioctl (req, vtable->get_profile_meta (ctx, in_val, &out_val), &out_val,
+ sizeof (out_val));
}
break;
case TRINITY_IOCTL_GET_PROFILE_BUFF: {
enum { KEY_HELP };
/** @brief The definitions of available options */
-static const struct fuse_opt trinity_cuse_opts[] = {
- TRINITY_OPT ("-M %u", major),
- TRINITY_OPT ("--maj=%u", major),
- TRINITY_OPT ("-m %u", minor),
- TRINITY_OPT ("--min=%u", minor),
- FUSE_OPT_KEY ("-h", KEY_HELP),
- FUSE_OPT_KEY ("--help", KEY_HELP),
- FUSE_OPT_END};
+static const struct fuse_opt trinity_cuse_opts[] = {TRINITY_OPT ("-M %u", major),
+ TRINITY_OPT ("--maj=%u", major),
+ TRINITY_OPT ("-m %u", minor),
+ TRINITY_OPT ("--min=%u", minor),
+ FUSE_OPT_KEY ("-h", KEY_HELP),
+ FUSE_OPT_KEY ("--help", KEY_HELP),
+ FUSE_OPT_END};
/** @brief Print the help message */
static void
/** @brief Parse the given arguments */
static int
-trinity_cuse_parse_args (void *data, const char *arg, int key,
- struct fuse_args *outargs) {
+trinity_cuse_parse_args (void *data, const char *arg, int key, struct fuse_args *outargs) {
trinity_cuse_param *param = (trinity_cuse_param *) data;
(void) outargs;
}
/** @brief trinity cuse driver's lowlevel ops */
-static const struct cuse_lowlevel_ops trinity_cuse_clop = {
- .init = nullptr,
- .init_done = nullptr,
- .destroy = nullptr,
- .open = trinity_cuse_open,
- .read = nullptr,
- .write = nullptr,
- .flush = nullptr,
- .release = trinity_cuse_release,
- .fsync = nullptr,
- .ioctl = trinity_cuse_ioctl,
- .poll = nullptr};
+static const struct cuse_lowlevel_ops trinity_cuse_clop = {.init = nullptr,
+ .init_done = nullptr,
+ .destroy = nullptr,
+ .open = trinity_cuse_open,
+ .read = nullptr,
+ .write = nullptr,
+ .flush = nullptr,
+ .release = trinity_cuse_release,
+ .fsync = nullptr,
+ .ioctl = trinity_cuse_ioctl,
+ .poll = nullptr};
/**
* @brief main routine of trinity-cuse
return -EPERM;
}
- if (fuse_opt_parse (&args, ¶m, trinity_cuse_opts,
- trinity_cuse_parse_args)) {
+ if (fuse_opt_parse (&args, ¶m, trinity_cuse_opts, trinity_cuse_parse_args)) {
std::cerr << "[Error] Failed to parse options\n";
return -EINVAL;
}
ci.dev_info_argv = dev_info_argv;
ci.flags = CUSE_UNRESTRICTED_IOCTL;
- return cuse_lowlevel_main (args.argc, args.argv, &ci, &trinity_cuse_clop,
- NULL);
+ return cuse_lowlevel_main (args.argc, args.argv, &ci, &trinity_cuse_clop, NULL);
}
}
/* Device Control */
int (*hwmem_alloc) (trinity_cuse_context *, const trinity_cuse_hwmem *);
int (*hwmem_dealloc) (trinity_cuse_context *, const trinity_cuse_hwmem *);
- int (*register_model) (trinity_cuse_context *, const trinity_cuse_model *,
- trinity_cuse_model *);
+ int (*register_model) (trinity_cuse_context *, const trinity_cuse_model *, trinity_cuse_model *);
int (*deregister_model) (trinity_cuse_context *, const uint64_t);
- int (*run_input) (trinity_cuse_context *, const trinity_cuse_input *,
- trinity_cuse_input *);
+ int (*run_input) (trinity_cuse_context *, const trinity_cuse_input *, trinity_cuse_input *);
int (*stop_requests) (trinity_cuse_context *);
int (*stop_request) (trinity_cuse_context *, const int);
/* Device Statistics/Profile */
int (*stat_apps) (trinity_cuse_context *, trinity_cuse_stat_apps *);
int (*stat_reqs) (trinity_cuse_context *, const trinity_cuse_stat_reqs *,
trinity_cuse_stat_reqs *);
- int (*get_profile_meta) (trinity_cuse_context *,
- const trinity_cuse_profile_meta *,
+ int (*get_profile_meta) (trinity_cuse_context *, const trinity_cuse_profile_meta *,
trinity_cuse_profile_meta *);
- int (*get_profile_buff) (trinity_cuse_context *,
- const trinity_cuse_profile_buff *,
+ int (*get_profile_buff) (trinity_cuse_context *, const trinity_cuse_profile_buff *,
trinity_cuse_profile_buff *, void *);
} trinity_cuse_ioctl_vtable;
type = NPUCOND_TRIV2_CONN_SOCIP;
if (dev_id < 0 || type == NPUCOND_CONN_UNKNOWN) {
- ss_ << "| Invalid device node provided: " << left << setw (29) << node_
- << "|\n";
+ ss_ << "| Invalid device node provided: " << left << setw (29) << node_ << "|\n";
ss_ << "+------------------------------------------------------------+\n";
return false;
app_id = strtol (nptr, &endptr, 10);
if (errno != 0 || nptr == endptr) {
- ss_ << "| Invalid app id provided: " << left << setw (34) << app_id_
- << "|\n";
+ ss_ << "| Invalid app id provided: " << left << setw (34) << app_id_ << "|\n";
ss_ << "+------------------------------------------------------------+\n";
return false;
optind = 0;
opterr = 0;
- while ((c = getopt_long (argc, argv, "hd:a:i:", longopts, (int *) 0)) !=
- EOF) {
+ while ((c = getopt_long (argc, argv, "hd:a:i:", longopts, (int *) 0)) != EOF) {
switch (c) {
case 'd':
set_device (optarg);
else if (optopt == 'i')
help_msg_ = "\nOption '-i' requires an extra argument\n";
else
- help_msg_ =
- "\nUnknown flag detected: " + to_string ((char) optopt) + "\n";
+ help_msg_ = "\nUnknown flag detected: " + to_string ((char) optopt) + "\n";
// no-break
case 'h':
help_only_ = true;