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 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "test/common/indexing_one_hot.h"
  2. #include "test/common/benchmarker.h"
  3. #include "test/cuda/fixture.h"
  4. #include "megcore_cuda.h"
  5. #include "megdnn/oprs/general.h"
  6. using namespace megdnn;
  7. using namespace test;
  8. TEST_F(CUDA, INDEXING_ONE_HOT) {
  9. run_indexing_one_hot_test(handle_cuda());
  10. }
  11. TEST_F(CUDA_ERROR_INFO, INDEXING_ONE_HOT) {
  12. ASSERT_EQ(0u, get_error_info().nr_error);
  13. bool failed = false;
  14. auto on_failure = [&failed, this]() {
  15. failed = true;
  16. auto err = get_error_info();
  17. ASSERT_GE(err.nr_error, 1u);
  18. printf("error msg: ");
  19. printf(err.msg, err.msg_args[0], err.msg_args[1], err.msg_args[2],
  20. err.msg_args[3]);
  21. printf("\n");
  22. };
  23. run_indexing_one_hot_test(handle_cuda(), on_failure);
  24. ASSERT_TRUE(failed);
  25. }
  26. TEST_F(CUDA, INDEXING_SET_ONE_HOT) {
  27. run_indexing_set_one_hot_test(handle_cuda());
  28. }
  29. #if MEGDNN_WITH_BENCHMARK
  30. TEST_F(CUDA, BENCHMARK_INDEXING_ONE_HOT) {
  31. Benchmarker<IndexingOneHot> bench{handle_cuda()};
  32. bench.set_times(1);
  33. UniformFloatRNG rng_val{-10, 10};
  34. UniformIntRNG rng_idx{0, 119};
  35. bench.set_param({2})
  36. .set_dtype(1, dtype::Int32{})
  37. .set_rng(1, &rng_idx)
  38. .set_rng(0, &rng_val);
  39. constexpr size_t A = 99, B = 41, C = 120, D = 191;
  40. auto time = bench.execs({{A, B, C, D}, {A, B, D}, {}}) * 1e-3;
  41. printf("bandwidth: %.2fGiB/s\n",
  42. A * B * D * sizeof(float) / 1024.0 / 1024 / 1024 / time);
  43. }
  44. #endif
  45. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}