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.

linspace.cpp 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * \file dnn/test/rocm/linspace.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #include "hcc_detail/hcc_defs_prologue.h"
  12. #include "test/rocm/fixture.h"
  13. #include "megdnn/oprs.h"
  14. #include "test/common/checker.h"
  15. #include "test/rocm/benchmarker.h"
  16. namespace megdnn {
  17. namespace test {
  18. TEST_F(ROCM, LINSPACE) {
  19. Checker<Linspace> checker(handle_rocm());
  20. Linspace::Param param;
  21. param.start = 0.5;
  22. param.stop = 1.5;
  23. param.endpoint = true;
  24. for (DType dtype :
  25. std::vector<DType>{dtype::Float16(), dtype::Int32(), dtype::Float32()}) {
  26. checker.set_dtype(0, dtype).set_param(param).exec(TensorShapeArray{{11}});
  27. }
  28. param.endpoint = false;
  29. for (DType dtype :
  30. std::vector<DType>{dtype::Float16(), dtype::Int32(), dtype::Float32()}) {
  31. checker.set_dtype(0, dtype).set_param(param).exec(TensorShapeArray{{11}});
  32. }
  33. }
  34. TEST_F(ROCM, LINSPACE_BENCHMARK) {
  35. ROCMBenchmarker<Linspace> benchmarker(handle_rocm(), handle_naive(false));
  36. benchmarker.set_display(true);
  37. Linspace::Param param{0.1, 9999.9, true};
  38. size_t sz = 50000;
  39. auto time_ms =
  40. benchmarker.set_dtype(0, dtype::Float32()).set_param(param).execs({{sz}});
  41. double bytes = sz * dtype::Float32().size();
  42. printf("vec size = %ld, bandwidth = %.2f GB/s\n", sz,
  43. (float)(bytes / (time_ms * 1e6)));
  44. }
  45. } // namespace test
  46. } // namespace megdnn
  47. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}