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.

sleep.cpp 1.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "../src/common/utils.h"
  2. #include "megdnn/oprs.h"
  3. #include "test/cuda/fixture.h"
  4. #include "test/cuda/utils.h"
  5. #include <chrono>
  6. #include <cstdio>
  7. #include <cuda_runtime_api.h>
  8. using namespace megdnn;
  9. using namespace test;
  10. TEST_F(CUDA, SLEEP) {
  11. auto opr = this->handle_cuda()->create_operator<megdnn::SleepForward>();
  12. auto run = [&](float time) -> double {
  13. opr->param() = {time};
  14. cuda_check(cudaDeviceSynchronize());
  15. auto t0 = std::chrono::high_resolution_clock::now();
  16. opr->exec();
  17. cuda_check(cudaDeviceSynchronize());
  18. auto t1 = std::chrono::high_resolution_clock::now();
  19. std::chrono::duration<double> diff = t1 - t0;
  20. return diff.count();
  21. };
  22. // warmv7up
  23. run(0.01);
  24. for (auto i : {0.1, 0.3}) {
  25. auto get = run(i);
  26. // sleep kernel in cuda is easily affected by the frequency change of
  27. // GPU, so we just print warn log instead assert. more refer to
  28. // XPU-226
  29. if (get < i || get > i * 2) {
  30. megdnn_log_warn("expect time between [%f, %f], got %f", i, 2 * i, get);
  31. }
  32. }
  33. }
  34. // vim: syntax=cpp.doxygen