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.

tqt.cpp 2.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * \file dnn/test/cuda/tqt.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
  10. * implied.
  11. */
  12. #include "test/common/tqt.h"
  13. #include "megdnn/oprs.h"
  14. #include "test/common/checker.h"
  15. #include "test/cuda/fixture.h"
  16. namespace megdnn {
  17. namespace test {
  18. using namespace tqt;
  19. TEST_F(CUDA, TQT) {
  20. std::vector<TestArg> args = get_args();
  21. auto dtype = dtype::Float32();
  22. for (auto&& arg : args) {
  23. auto param = arg.param;
  24. auto ishape = arg.ishape;
  25. auto scale_shape = arg.scale_shape;
  26. Checker<TQTForward> checker(handle_cuda());
  27. checker.set_param(param)
  28. .set_dtype(0, dtype)
  29. .set_dtype(1, dtype)
  30. .set_dtype(2, dtype)
  31. .execs({ishape, scale_shape, ishape});
  32. }
  33. // test noncontiguous layout
  34. for (auto&& arg : args) {
  35. auto param = arg.param;
  36. auto ishape = arg.ishape;
  37. auto sshape = arg.scale_shape;
  38. Checker<TQTForward> checker(handle_cuda());
  39. TensorLayout ilayout(
  40. ishape,
  41. {(long int)(ishape[1] * ishape[2] * ishape[3] * 2),
  42. (long int)(ishape[2] * ishape[3]), (long int)ishape[3], 1},
  43. dtype::Float32());
  44. checker.set_param(param).execl({ilayout, {sshape, dtype::Float32()}, ilayout});
  45. }
  46. }
  47. TEST_F(CUDA, TQT_BACKWARD) {
  48. std::vector<TestArg> args = get_args();
  49. auto dtype = dtype::Float32();
  50. for (auto&& arg : args) {
  51. auto param = arg.param;
  52. auto ishape = arg.ishape;
  53. auto scale_shape = arg.scale_shape;
  54. Checker<TQTBackward> checker(handle_cuda());
  55. checker.set_param(param)
  56. .set_dtype(0, dtype)
  57. .set_dtype(1, dtype)
  58. .set_dtype(2, dtype)
  59. .set_dtype(3, dtype)
  60. .set_dtype(4, dtype)
  61. .execs({ishape, ishape, scale_shape, ishape, ishape});
  62. }
  63. // test noncontiguous layout
  64. for (auto&& arg : args) {
  65. auto param = arg.param;
  66. auto ishape = arg.ishape;
  67. auto sshape = arg.scale_shape;
  68. Checker<TQTBackward> checker(handle_cuda());
  69. TensorLayout ilayout(
  70. ishape,
  71. {(long int)(ishape[1] * ishape[2] * ishape[3] * 2),
  72. (long int)(ishape[2] * ishape[3]), (long int)ishape[3], 1},
  73. dtype::Float32());
  74. checker.set_param(param).execl(
  75. {ilayout, ilayout, {sshape, dtype::Float32()}, ilayout, ilayout});
  76. }
  77. }
  78. } // namespace test
  79. } // namespace megdnn

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