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.

indexing_one_hot.cpp 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * \file dnn/test/rocm/indexing_one_hot.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/common/benchmarker.h"
  13. #include "test/common/indexing_one_hot.h"
  14. #include "test/rocm/fixture.h"
  15. #include "megcore_rocm.h"
  16. #include "megdnn/oprs/general.h"
  17. #include "test/rocm/benchmarker.h"
  18. using namespace megdnn;
  19. using namespace test;
  20. TEST_F(ROCM, INDEXING_ONE_HOT) {
  21. run_indexing_one_hot_test(handle_rocm());
  22. }
  23. TEST_F(ROCM_ERROR_INFO, INDEXING_ONE_HOT) {
  24. ASSERT_EQ(0u, get_error_info().nr_error);
  25. bool failed = false;
  26. auto on_failure = [&failed, this]() {
  27. failed = true;
  28. auto err = get_error_info();
  29. ASSERT_GE(err.nr_error, 1u);
  30. printf("error msg: ");
  31. printf(err.msg, err.msg_args[0], err.msg_args[1], err.msg_args[2],
  32. err.msg_args[3]);
  33. printf("\n");
  34. };
  35. run_indexing_one_hot_test(handle_rocm(), on_failure);
  36. ASSERT_TRUE(failed);
  37. }
  38. TEST_F(ROCM, INDEXING_ONE_HOT_BENCHMARK) {
  39. megdnn::rocm::enable_miopen_algo_search(handle_rocm(), true);
  40. auto benchmarker = ROCMBenchmarker<IndexingOneHotForward>(
  41. handle_rocm(), handle_naive(false));
  42. UniformFloatRNG rng_val{-10, 10};
  43. UniformIntRNG rng_idx{0, 119};
  44. benchmarker.set_display(true);
  45. benchmarker.set_param({2})
  46. .set_dtype(1, dtype::Int32{})
  47. .set_rng(1, &rng_idx)
  48. .set_rng(0, &rng_val);
  49. constexpr size_t A = 99, B = 41, C = 120, D = 191;
  50. benchmarker.execs({{A, B, C, D}, {A, B, D}, {}});
  51. auto time = benchmarker.execs({{A, B, C, D}, {A, B, D}, {}});
  52. time = benchmarker.execs({{A, B, C, D}, {A, B, D}, {}});
  53. printf("bandwidth: %.2fGiB/s\n", A * B * D * sizeof(float) / (1e6 * time));
  54. }
  55. TEST_F(ROCM, INDEXING_SET_ONE_HOT) {
  56. run_indexing_set_one_hot_test(handle_rocm());
  57. }
  58. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

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