utils.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef WASI_NN_UTILS
  6. #define WASI_NN_UTILS
  7. #include <stdint.h>
  8. #include "wasi_nn.h"
  9. #define MAX_MODEL_SIZE 85000000
  10. #define MAX_OUTPUT_TENSOR_SIZE 200
  11. #define INPUT_TENSOR_DIMS 4
  12. #define EPSILON 1e-8
  13. typedef struct {
  14. float *input_tensor;
  15. uint32_t *dim;
  16. uint32_t elements;
  17. } input_info;
  18. /* wasi-nn wrappers */
  19. error
  20. wasm_load(char *model_name, graph *g, execution_target target);
  21. error
  22. wasm_init_execution_context(graph g, graph_execution_context *ctx);
  23. error
  24. wasm_set_input(graph_execution_context ctx, float *input_tensor, uint32_t *dim);
  25. error
  26. wasm_compute(graph_execution_context ctx);
  27. error
  28. wasm_get_output(graph_execution_context ctx, uint32_t index, float *out_tensor,
  29. uint32_t *out_size);
  30. /* Utils */
  31. float *
  32. run_inference(execution_target target, float *input, uint32_t *input_size,
  33. uint32_t *output_size, char *model_name,
  34. uint32_t num_output_tensors);
  35. input_info
  36. create_input(int *dims);
  37. #endif