| 119 | |
| 120 | template <typename Backend> |
| 121 | void 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 | |
| 161 | template<typename Backend> |
nothing calls this directly
no test coverage detected