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

Method WriteDataBHWC

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

Source from the content-addressed store, hash-verified

94}
95
96Status Tensor::WriteDataBHWC(absl::Span<const float> in,
97 CLCommandQueue* queue) {
98 if (in.size() != channels_ * width_ * height_) {
99 return InvalidArgumentError("Input data size not match expected size");
100 }
101
102 void* data_ptr = nullptr;
103 int channels = storage_type_ == TensorStorageType::SINGLE_TEXTURE_2D
104 ? channels_
105 : AlignByN(channels_, 4);
106 const int elements_count = width_ * height_ * channels;
107
108 const size_t data_size = elements_count * SizeOf(data_type_);
109 std::vector<float> data_f;
110 std::vector<half> data_h;
111 if (data_type_ == DataType::FLOAT32) {
112 data_f.resize(elements_count);
113 data_ptr = data_f.data();
114 DataFromBHWC(in, absl::MakeSpan(data_f.data(), data_f.size()));
115 } else {
116 data_h.resize(elements_count);
117 data_ptr = data_h.data();
118 DataFromBHWC(in, absl::MakeSpan(data_h.data(), data_h.size()));
119 }
120
121 switch (storage_type_) {
122 case TensorStorageType::BUFFER: {
123 RETURN_IF_ERROR(queue->EnqueueWriteBuffer(memory_, data_size, data_ptr));
124 break;
125 }
126 case TensorStorageType::TEXTURE_ARRAY:
127 case TensorStorageType::TEXTURE_2D:
128 case TensorStorageType::SINGLE_TEXTURE_2D:
129 RETURN_IF_ERROR(
130 queue->EnqueueWriteImage(memory_, GetFullTensorRegion(), data_ptr));
131 break;
132 default:
133 return InternalError("Unsupported tensor storage type");
134 }
135
136 return OkStatus();
137}
138
139Status Tensor::WriteData(CLCommandQueue* queue, const TensorFloat32& src) {
140 RETURN_IF_ERROR(IsValid(src.shape));

Callers

nothing calls this directly

Calls 10

AlignByNFunction · 0.85
OkStatusFunction · 0.85
EnqueueWriteBufferMethod · 0.80
EnqueueWriteImageMethod · 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