| 123 | return true; |
| 124 | } |
| 125 | PerformanceResult proxy_kernel( |
| 126 | TensorNDArray tensor_array, StdKernelCall func, StdKernelInitCall init_func, |
| 127 | StdKernelWorkspaceCall workspace_func, StdKernelDeduceCall deduce_func, |
| 128 | const BenchmarkOption& benchmark_option, const size_t workspace_bytes, |
| 129 | OutputScope output_idx) { |
| 130 | constexpr size_t mem_align_bytes = 64; |
| 131 | megdnn::SmallVector<Tensor> cc_tensor_in; |
| 132 | megdnn::SmallVector<std::string> cc_tensor_in_name; |
| 133 | megdnn::SmallVector<Tensor> cc_tensor_out; |
| 134 | for (int i = output_idx.start; i <= output_idx.end; ++i) { |
| 135 | cc_tensor_out.push_back(dnntensor_2_cctensor(tensor_array.at(i), "cc_output")); |
| 136 | } |
| 137 | size_t input_cnt = 0; |
| 138 | for (size_t i = 0; i < tensor_array.size(); ++i) { |
| 139 | if ((int)i >= output_idx.start && (int)i <= output_idx.end) { |
| 140 | continue; |
| 141 | } |
| 142 | cc_tensor_in_name.push_back(mgb::ssprintf("cc_input:%zu", input_cnt++)); |
| 143 | cc_tensor_in.push_back(dnntensor_2_cctensor( |
| 144 | tensor_array[i], cc_tensor_in_name.back().c_str())); |
| 145 | } |
| 146 | auto make_pointer_array = [](auto&& data_vec) { |
| 147 | std::vector<decltype(data_vec.data())> ret; |
| 148 | ret.reserve(data_vec.size()); |
| 149 | for (auto&& i : data_vec) { |
| 150 | ret.push_back(&i); |
| 151 | } |
| 152 | return ret; |
| 153 | }; |
| 154 | //! get workspace size should be ahead of init function |
| 155 | auto input_ptr_array = make_pointer_array(cc_tensor_in); |
| 156 | auto output_ptr_array = make_pointer_array(cc_tensor_out); |
| 157 | |
| 158 | size_t workspace_size = 0; |
| 159 | workspace_func(input_ptr_array.data(), input_ptr_array.size(), 1, &workspace_size); |
| 160 | mgb_assert( |
| 161 | workspace_bytes == workspace_size, |
| 162 | "two method workspace must equal, jit get %zu, runtime get %zu\n", |
| 163 | workspace_bytes, workspace_size); |
| 164 | std::vector<std::vector<char>> preprocessed_weight_storage; |
| 165 | if (init_func) { |
| 166 | int nr_weight_after_process = 0; |
| 167 | |
| 168 | auto input_ptr_array = make_pointer_array(cc_tensor_in); |
| 169 | init_func( |
| 170 | input_ptr_array.data(), input_ptr_array.size(), NULL, |
| 171 | &nr_weight_after_process, nullptr); |
| 172 | |
| 173 | if (nr_weight_after_process) { |
| 174 | std::vector<Tensor> new_cc_weight_vec(nr_weight_after_process); |
| 175 | preprocessed_weight_storage.resize(nr_weight_after_process); |
| 176 | init_func( |
| 177 | input_ptr_array.data(), input_ptr_array.size(), |
| 178 | new_cc_weight_vec.data(), NULL, nullptr); |
| 179 | for (int i = 0; i < nr_weight_after_process; ++i) { |
| 180 | size_t size_in_bytes = tensor_length_in_byte(&new_cc_weight_vec[i]); |
| 181 | preprocessed_weight_storage[i].resize(size_in_bytes); |
| 182 | new_cc_weight_vec[i].ptr = preprocessed_weight_storage[i].data(); |
no test coverage detected