24 #ifndef MXNET_COMMON_EXEC_UTILS_H_ 25 #define MXNET_COMMON_EXEC_UTILS_H_ 28 #include "../common/utils.h" 47 std::vector<TBlob> *blobs,
48 std::vector<NDArray> *temp_src,
49 std::vector<NDArray> *temp_dst,
50 std::unordered_map<uint32_t, uint32_t> *idx_map =
nullptr) {
51 bool require_cast =
false;
52 for (
size_t i = 0; i < src.size(); i++) {
55 if (idx_map !=
nullptr) {
56 (*idx_map)[i] = temp_dst->size();
58 NDArray temp(nd.shape(), nd.ctx(),
false, nd.dtype());
59 temp_src->emplace_back(nd);
60 temp_dst->emplace_back(temp);
61 blobs->emplace_back(temp.data());
64 blobs->push_back(nd.data());
78 const std::vector<NDArray> &ndoutputs,
79 std::vector<TBlob> *input_blobs,
80 std::vector<TBlob> *output_blobs,
81 std::vector<NDArray> *pre_temp_src,
82 std::vector<NDArray> *pre_temp_dst,
83 std::vector<NDArray> *post_temp_src,
84 std::vector<NDArray> *post_temp_dst,
85 std::unordered_map<uint32_t, uint32_t> *in_temp_idx_map,
86 const std::vector<uint32_t> &mutate_idx) {
88 SetupDefaultBlobs(ndinputs, input_blobs, pre_temp_src, pre_temp_dst, in_temp_idx_map);
92 for (
const auto idx : mutate_idx) {
93 auto map_iter = in_temp_idx_map->find(idx);
94 if (map_iter != in_temp_idx_map->end()) {
95 post_temp_src->push_back(pre_temp_dst->at(map_iter->second));
96 post_temp_dst->push_back(ndinputs[idx]);
109 const std::vector<NDArray>& dst,
112 CHECK_EQ(dst.size(), src.size());
113 for (
size_t i = 0; i < src.size(); i++) {
116 CastStorageDispatch<gpu>(ctx, src[i], dst[i]);
121 CastStorageDispatch<cpu>(ctx, src[i], dst[i]);
127 #endif // MXNET_COMMON_EXEC_UTILS_H_
#define MXNET_GPU_NOT_ENABLED_ERROR
Error message for using gpu when MXNET_USE_CUDA==0.
Definition: base.h:68
namespace of mxnet
Definition: base.h:127
All the possible information needed by Operator.Forward and Backward This is the superset of RunConte...
Definition: op_attr_types.h:66
bool SetupDefaultBlobs(const std::vector< NDArray > &src, std::vector< TBlob > *blobs, std::vector< NDArray > *temp_src, std::vector< NDArray > *temp_dst, std::unordered_map< uint32_t, uint32_t > *idx_map=nullptr)
Definition: exec_utils.h:46
void SetupDefaultBlobsInOut(const std::vector< NDArray > &ndinputs, const std::vector< NDArray > &ndoutputs, std::vector< TBlob > *input_blobs, std::vector< TBlob > *output_blobs, std::vector< NDArray > *pre_temp_src, std::vector< NDArray > *pre_temp_dst, std::vector< NDArray > *post_temp_src, std::vector< NDArray > *post_temp_dst, std::unordered_map< uint32_t, uint32_t > *in_temp_idx_map, const std::vector< uint32_t > &mutate_idx)
Definition: exec_utils.h:77
void CastNonDefaultStorage(const std::vector< NDArray > &src, const std::vector< NDArray > &dst, const OpContext &ctx, const bool is_gpu)
Definition: exec_utils.h:108
ndarray interface
Definition: ndarray.h:79