commonmodel.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <cfloat>
  3. #include <cstdlib>
  4. #include <memory>
  5. #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
  6. #ifdef __APPLE__
  7. #include <OpenCL/cl.h>
  8. #else
  9. #include <CL/cl.h>
  10. #endif
  11. #include "common/mat.h"
  12. #include "cereal/messaging/messaging.h"
  13. #include "selfdrive/modeld/transforms/loadyuv.h"
  14. #include "selfdrive/modeld/transforms/transform.h"
  15. const bool send_raw_pred = getenv("SEND_RAW_PRED") != NULL;
  16. void softmax(const float* input, float* output, size_t len);
  17. float sigmoid(float input);
  18. template<class T, size_t size>
  19. constexpr const kj::ArrayPtr<const T> to_kj_array_ptr(const std::array<T, size> &arr) {
  20. return kj::ArrayPtr(arr.data(), arr.size());
  21. }
  22. class ModelFrame {
  23. public:
  24. ModelFrame(cl_device_id device_id, cl_context context);
  25. ~ModelFrame();
  26. float* prepare(cl_mem yuv_cl, int width, int height, int frame_stride, int frame_uv_offset, const mat3& transform, cl_mem *output);
  27. const int MODEL_WIDTH = 512;
  28. const int MODEL_HEIGHT = 256;
  29. const int MODEL_FRAME_SIZE = MODEL_WIDTH * MODEL_HEIGHT * 3 / 2;
  30. const int buf_size = MODEL_FRAME_SIZE * 2;
  31. private:
  32. Transform transform;
  33. LoadYUVState loadyuv;
  34. cl_command_queue q;
  35. cl_mem y_cl, u_cl, v_cl, net_input_cl;
  36. std::unique_ptr<float[]> input_frames;
  37. };