MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ReadDataBHWC

Method ReadDataBHWC

tensorflow/lite/delegates/gpu/cl/tensor.cc:144–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144Status Tensor::ReadDataBHWC(absl::Span<float> out,
145 CLCommandQueue* queue) const {
146 if (out.size() != channels_ * width_ * height_) {
147 return InvalidArgumentError("Output data size not match expected size");
148 }
149
150 void* data_ptr = nullptr;
151 int channels = storage_type_ == TensorStorageType::SINGLE_TEXTURE_2D
152 ? channels_
153 : AlignByN(channels_, 4);
154 const int elements_count = width_ * height_ * channels;
155 const size_t data_size = elements_count * SizeOf(data_type_);
156 std::vector<float> data_f;
157 std::vector<half> data_h;
158 if (data_type_ == DataType::FLOAT32) {
159 data_f.resize(elements_count);
160 data_ptr = data_f.data();
161 } else {
162 data_h.resize(elements_count);
163 data_ptr = data_h.data();
164 }
165
166 switch (storage_type_) {
167 case TensorStorageType::BUFFER:
168 RETURN_IF_ERROR(queue->EnqueueReadBuffer(memory_, data_size, data_ptr));
169 break;
170 case TensorStorageType::TEXTURE_ARRAY:
171 case TensorStorageType::TEXTURE_2D:
172 case TensorStorageType::SINGLE_TEXTURE_2D:
173 RETURN_IF_ERROR(
174 queue->EnqueueReadImage(memory_, GetFullTensorRegion(), data_ptr));
175 break;
176 default:
177 return InternalError("Unsupported tensor storage type");
178 }
179
180 if (data_type_ == DataType::FLOAT32) {
181 DataToBHWC(absl::MakeConstSpan(data_f.data(), data_f.size()), out);
182 } else {
183 DataToBHWC(absl::MakeConstSpan(data_h.data(), data_h.size()), out);
184 }
185
186 return OkStatus();
187}
188
189Status Tensor::ReadData(CLCommandQueue* queue, TensorFloat32* dst) const {
190 RETURN_IF_ERROR(IsValid(dst->shape));

Calls 10

AlignByNFunction · 0.85
OkStatusFunction · 0.85
EnqueueReadBufferMethod · 0.80
EnqueueReadImageMethod · 0.80
InvalidArgumentErrorFunction · 0.50
SizeOfFunction · 0.50
InternalErrorFunction · 0.50
sizeMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected