| 169 | |
| 170 | template<typename inType, typename outType> |
| 171 | void copy(const Param out, const Param in, dim_t ondims, |
| 172 | const outType default_value, const double factor) { |
| 173 | dims_type idims_{ |
| 174 | static_cast<int>(in.info.dims[0]), static_cast<int>(in.info.dims[1]), |
| 175 | static_cast<int>(in.info.dims[2]), static_cast<int>(in.info.dims[3])}; |
| 176 | dims_type istrides_{static_cast<int>(in.info.strides[0]), |
| 177 | static_cast<int>(in.info.strides[1]), |
| 178 | static_cast<int>(in.info.strides[2]), |
| 179 | static_cast<int>(in.info.strides[3])}; |
| 180 | dims_type odims_{ |
| 181 | static_cast<int>(out.info.dims[0]), static_cast<int>(out.info.dims[1]), |
| 182 | static_cast<int>(out.info.dims[2]), static_cast<int>(out.info.dims[3])}; |
| 183 | dims_type ostrides_{static_cast<int>(out.info.strides[0]), |
| 184 | static_cast<int>(out.info.strides[1]), |
| 185 | static_cast<int>(out.info.strides[2]), |
| 186 | static_cast<int>(out.info.strides[3])}; |
| 187 | int ondims_{static_cast<int>(ondims)}; |
| 188 | const size_t totalSize{odims_.dims[0] * odims_.dims[1] * odims_.dims[2] * |
| 189 | odims_.dims[3] * sizeof(outType) + |
| 190 | idims_.dims[0] * idims_.dims[1] * idims_.dims[2] * |
| 191 | idims_.dims[3] * sizeof(inType)}; |
| 192 | bool same_dims{true}; |
| 193 | for (int i{0}; i < ondims_; ++i) { |
| 194 | if (idims_.dims[i] > odims_.dims[i]) { |
| 195 | idims_.dims[i] = odims_.dims[i]; |
| 196 | } else if (idims_.dims[i] != odims_.dims[i]) { |
| 197 | same_dims = false; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | removeEmptyColumns(odims_.dims, ondims_, idims_.dims, istrides_.dims); |
| 202 | ondims_ = |
| 203 | removeEmptyColumns(odims_.dims, ondims_, odims_.dims, ostrides_.dims); |
| 204 | ondims_ = combineColumns(odims_.dims, ostrides_.dims, ondims_, idims_.dims, |
| 205 | istrides_.dims); |
| 206 | |
| 207 | constexpr int factorTypeIdx{std::is_same<inType, double>::value || |
| 208 | std::is_same<inType, cdouble>::value}; |
| 209 | const char* factorType[]{"float", "double"}; |
| 210 | |
| 211 | const std::array<TemplateArg, 5> targs{ |
| 212 | TemplateTypename<inType>(), TemplateTypename<outType>(), |
| 213 | TemplateArg(same_dims), TemplateArg(factorType[factorTypeIdx]), |
| 214 | TemplateArg(factor != 1.0), |
| 215 | }; |
| 216 | const std::array<std::string, 8> options{ |
| 217 | DefineKeyValue(inType, dtype_traits<inType>::getName()), |
| 218 | DefineKeyValue(outType, dtype_traits<outType>::getName()), |
| 219 | std::string(" -D inType_") + dtype_traits<inType>::getName(), |
| 220 | std::string(" -D outType_") + dtype_traits<outType>::getName(), |
| 221 | DefineKeyValue(SAME_DIMS, static_cast<int>(same_dims)), |
| 222 | std::string(" -D factorType=") + factorType[factorTypeIdx], |
| 223 | std::string((factor != 1.0) ? " -D FACTOR" : " -D NOFACTOR"), |
| 224 | getTypeBuildDefinition<inType, outType>(), |
| 225 | }; |
| 226 | |
| 227 | threadsMgt<int> th(odims_.dims, ondims_, 1, 1, totalSize, sizeof(outType)); |
| 228 | auto copy = common::getKernel(th.loop0 ? "scaledCopyLoop0" |
no test coverage detected