MCPcopy Create free account
hub / github.com/NVIDIA/DALI / SetExternalInput

Function SetExternalInput

dali/c_api/c_api.cc:121–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119
120template <typename Backend>
121void SetExternalInput(daliPipelineHandle_t pipe_handle, const char *name, const void *data_ptr,
122 dali_data_type_t data_type, const int64_t *shapes, int sample_dim,
123 const char *layout_str, cudaStream_t stream = 0, unsigned int flags = 0) {
124 dali::Pipeline *pipeline = (*pipe_handle)->pipeline.get();
125 auto *bs_map = &(*pipe_handle)->batch_size_map;
126 auto *data_id_map = &(*pipe_handle)->data_id_map;
127 auto curr_batch_size = PopCurrBatchSize(bs_map, pipeline->max_batch_size(), name);
128 std::vector<int64_t> shapes_tmp(shapes, shapes + sample_dim * curr_batch_size);
129 dali::TensorListShape<> tl_shape(std::move(shapes_tmp), curr_batch_size, sample_dim);
130 dali::TensorLayout layout{};
131 if (layout_str != nullptr) {
132 layout = dali::TensorLayout(layout_str);
133 }
134 dali::TensorList<Backend> data;
135 auto type_id = static_cast<dali::DALIDataType>(data_type);
136 auto elem_sizeof = dali::TypeTable::GetTypeInfo(type_id).size();
137 // We cast away the const from data_ptr, as there is no other way of passing it to the
138 // TensorList, as we must also set the shape and type metadata.
139 // It is passed further as const TensorList, so it's data cannot be modified.
140 AccessOrder order;
141 if (std::is_same_v<Backend, GPUBackend> || (flags & DALI_ext_pinned))
142 order = AccessOrder(stream);
143 else
144 order = AccessOrder::host();
145 // We do not support feeding memory cross-device, it is assumed it's on the current device
146 // that is tied to the pipeline.
147 int device_id = pipeline->device_id();
148 data.ShareData(std::shared_ptr<void>(const_cast<void *>(data_ptr), [](void *) {}),
149 tl_shape.num_elements() * elem_sizeof, flags & DALI_ext_pinned, tl_shape, type_id,
150 device_id, order);
151 data.SetLayout(layout);
152
153 auto data_id = data_id_map->extract(name);
154
155 pipeline->SetExternalInput(name, data, order, flags & DALI_ext_force_sync,
156 flags & DALI_use_copy_kernel, GetExternalSourceCopyMode(flags),
157 data_id ? std::make_optional(data_id.mapped()) : std::nullopt);
158}
159
160
161template<typename Backend>

Callers

nothing calls this directly

Calls 13

PopCurrBatchSizeFunction · 0.85
GetTypeInfoFunction · 0.85
AccessOrderFunction · 0.85
max_batch_sizeMethod · 0.80
TensorLayoutClass · 0.50
hostFunction · 0.50
getMethod · 0.45
sizeMethod · 0.45
device_idMethod · 0.45
ShareDataMethod · 0.45
num_elementsMethod · 0.45

Tested by

no test coverage detected