You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

extra_impl_helper.cpp 1.1 kB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "test/common/extra_impl_helper.h"
  2. namespace megdnn {
  3. namespace test {
  4. template <>
  5. std::function<void(const TensorNDArray&)> extra_impl_helper<AddUpdate>(
  6. Handle* h, const AddUpdate::Param& p) {
  7. auto impl = [](const TensorNDArray& tensors, Handle* h, const AddUpdate::Param& p) {
  8. auto fp32_opr = h->create_operator<AddUpdate>();
  9. auto type_cvt = h->create_operator<TypeCvt>();
  10. fp32_opr->param() = p;
  11. TensorNDArray fp32_tensors;
  12. for (size_t i = 0; i < tensors.size(); ++i) {
  13. auto layout = tensors[i].layout;
  14. layout.dtype = dtype::Float32();
  15. fp32_tensors.emplace_back(malloc(layout.span().dist_byte()), layout);
  16. type_cvt->exec(tensors[i], fp32_tensors[i]);
  17. }
  18. fp32_opr->exec(fp32_tensors[0], fp32_tensors[1]);
  19. type_cvt->exec(fp32_tensors[0], tensors[0]);
  20. for (size_t i = 0; i < tensors.size(); ++i) {
  21. free(fp32_tensors[i].raw_ptr());
  22. }
  23. };
  24. return std::bind(impl, std::placeholders::_1, h, std::cref(p));
  25. }
  26. } // namespace test
  27. } // namespace megdnn
  28. // vim: syntax=cpp.doxygen