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.

mesh_indexing.cpp 5.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /**
  2. * \file dnn/test/cuda/mesh_indexing.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 implied.
  10. */
  11. #include "test/common/mesh_indexing.h"
  12. #include "megdnn/basic_types.h"
  13. #include "test/common/checker.h"
  14. #include "test/common/index.h"
  15. #include "test/cuda/fixture.h"
  16. using namespace megdnn;
  17. using namespace test;
  18. TEST_F(CUDA, MESH_INDEXING) {
  19. Checker<MeshIndexing> checker(handle_cuda());
  20. size_t idx_size0, idx_size1;
  21. IndexRNG rng0{idx_size0, 2}, rng1{idx_size1, 3};
  22. checker.set_dtype(0, dtype::Float32())
  23. .set_dtype(1, dtype::Float32())
  24. .set_dtype(2, dtype::Int32())
  25. .set_dtype(3, dtype::Int32())
  26. .set_rng(2, &rng0)
  27. .set_rng(3, &rng1);
  28. SmallVector<size_t> init_axes;
  29. idx_size0 = 23;
  30. init_axes = {0};
  31. checker.set_proxy({init_axes})
  32. .execs({{23}, {100}, {100}})
  33. .execs({{23, 5}, {100, 5}, {100}});
  34. idx_size0 = 3;
  35. init_axes = {1};
  36. checker.set_proxy({init_axes})
  37. .execs({{2, 3}, {2, 10}, {10}})
  38. .execs({{2, 3, 5}, {2, 50, 5}, {50}})
  39. .execs({{2, 3, 5, 7}, {2, 55, 5, 7}, {55}});
  40. idx_size0 = 23;
  41. idx_size1 = 17;
  42. init_axes = {3, 1};
  43. checker.set_proxy({init_axes})
  44. .execs({{3, 17, 9, 23}, {3, 100, 9, 100}, {100}, {100}})
  45. .execs({{3, 17, 29, 30}, {3, 66, 29, 99}, {99}, {66}});
  46. }
  47. TEST_F(CUDA, BATCHED_MESH_INDEXING) {
  48. Checker<BatchedMeshIndexing> checker(handle_cuda());
  49. size_t idx_size0, idx_size1;
  50. IndexRNG rng0{idx_size0, 2}, rng1{idx_size1, 3};
  51. checker.set_dtype(0, dtype::Float32())
  52. .set_dtype(1, dtype::Float32())
  53. .set_dtype(2, dtype::Int32())
  54. .set_dtype(3, dtype::Int32())
  55. .set_rng(2, &rng0)
  56. .set_rng(3, &rng1);
  57. SmallVector<size_t> init_axes;
  58. init_axes = {1};
  59. idx_size0 = 5;
  60. checker.set_proxy({init_axes}).execs({{2, 5}, {2, 3}, {2, 3}});
  61. idx_size0 = 23;
  62. idx_size1 = 17;
  63. init_axes = {3, 1};
  64. checker.set_proxy({init_axes})
  65. .execs({{3, 17, 9, 23}, {3, 100, 9, 100}, {3, 100}, {3, 100}})
  66. .execs({{3, 17, 29, 30}, {3, 66, 29, 99}, {3, 99}, {3, 66}});
  67. idx_size0 = 5;
  68. init_axes = {1};
  69. TensorLayout index_layout{TensorShape{1, 3}, dtype::Int32()};
  70. index_layout = index_layout.broadcast({2, 3});
  71. checker.set_proxy({init_axes})
  72. .execl({TensorLayout{TensorShape{2, idx_size0}, dtype::Float32()},
  73. TensorLayout{TensorShape{2, 3}, dtype::Float32()}, index_layout});
  74. }
  75. namespace {
  76. template <typename T, typename RNG>
  77. void run_modify_test(Handle* handle) {
  78. Checker<T> checker(handle);
  79. size_t idx_size0, idx_size1;
  80. RNG rng0{idx_size0, 2}, rng1{idx_size1, 3};
  81. checker.set_dtype(0, dtype::Float32())
  82. .set_dtype(1, dtype::Float32())
  83. .set_dtype(2, dtype::Int32())
  84. .set_dtype(3, dtype::Int32())
  85. .set_rng(2, &rng0)
  86. .set_rng(3, &rng1);
  87. SmallVector<size_t> init_axes;
  88. idx_size0 = 230;
  89. init_axes = {0};
  90. checker.set_proxy({init_axes})
  91. .execs({{230}, {100}, {100}})
  92. .execs({{230, 5}, {100, 5}, {100}});
  93. idx_size0 = 30;
  94. init_axes = {1};
  95. checker.set_proxy(init_axes)
  96. .execs({{2, 30}, {2, 10}, {10}})
  97. .execs({{2, 30, 5}, {2, 20, 5}, {20}})
  98. .execs({{2, 30, 5, 7}, {2, 25, 5, 7}, {25}});
  99. }
  100. template <typename T, typename RNG>
  101. void run_batch_modify_test(Handle* handle) {
  102. Checker<T> checker(handle);
  103. size_t idx_size0, idx_size1;
  104. RNG rng0{idx_size0, 2}, rng1{idx_size1, 3};
  105. checker.set_dtype(0, dtype::Float32())
  106. .set_dtype(1, dtype::Float32())
  107. .set_dtype(2, dtype::Int32())
  108. .set_dtype(3, dtype::Int32())
  109. .set_rng(2, &rng0)
  110. .set_rng(3, &rng1);
  111. SmallVector<size_t> init_axes;
  112. init_axes = {1};
  113. idx_size0 = 5;
  114. checker.set_proxy({init_axes}).execs({{2, 5}, {2, 3}, {2, 3}});
  115. idx_size0 = 23;
  116. idx_size1 = 17;
  117. init_axes = {3, 1};
  118. checker.set_proxy({init_axes})
  119. .execs({{3, 17, 9, 23}, {3, 10, 9, 10}, {3, 10}, {3, 10}})
  120. .execs({{3, 17, 29, 30}, {3, 11, 29, 22}, {3, 22}, {3, 11}});
  121. }
  122. } // namespace
  123. TEST_F(CUDA, MESH_MODIFY_INCREMENT) {
  124. run_modify_test<IncrMeshIndexing, IndexRNG>(handle_cuda());
  125. }
  126. TEST_F(CUDA, MESH_MODIFY_SETTING) {
  127. run_modify_test<SetMeshIndexing, mesh_indexing::NoReplacementIndexRNG>(
  128. handle_cuda());
  129. }
  130. TEST_F(CUDA, BATCHED_MESH_MODIFY_INCREMENT) {
  131. run_batch_modify_test<BatchedIncrMeshIndexing, IndexRNG>(handle_cuda());
  132. }
  133. TEST_F(CUDA, BATCHED_MESH_MODIFY_SETTING) {
  134. run_batch_modify_test<BatchedSetMeshIndexing, mesh_indexing::NoReplacementIndexRNG>(
  135. handle_cuda());
  136. }