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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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-2020 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. {
  20. Checker<Linspace> checker(handle_rocm());
  21. Linspace::Param param;
  22. param.start = 0.5;
  23. param.stop = 1.5;
  24. param.endpoint = true;
  25. for (DType dtype: std::vector<DType>{
  26. dtype::Float16(), dtype::Int32(), dtype::Float32()}) {
  27. checker.set_dtype(0, dtype).set_param(param).exec(
  28. TensorShapeArray{{11}});
  29. }
  30. param.endpoint = false;
  31. for (DType dtype: std::vector<DType>{
  32. dtype::Float16(), dtype::Int32(), dtype::Float32()}) {
  33. checker.set_dtype(0, dtype).set_param(param).exec(
  34. TensorShapeArray{{11}});
  35. }
  36. }
  37. TEST_F(ROCM, LINSPACE_BENCHMARK)
  38. {
  39. ROCMBenchmarker<Linspace> benchmarker(handle_rocm(), handle_naive(false));
  40. benchmarker.set_display(true);
  41. Linspace::Param param{0.1, 9999.9, true};
  42. size_t sz = 50000;
  43. auto time_ms = benchmarker.set_dtype(0, dtype::Float32())
  44. .set_param(param).execs({{sz}});
  45. double bytes = sz * dtype::Float32().size();
  46. printf("vec size = %ld, bandwidth = %.2f GB/s\n", sz, (float)(bytes / (time_ms * 1e6)));
  47. }
  48. } // namespace test
  49. } // namespace megdnn
  50. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台