| 87 | |
| 88 | template <DataType T> |
| 89 | Status ConvTexture::UploadWeights(const ::tflite::gpu::Tensor<OHWI, T>& weights, |
| 90 | CLContext* context) { |
| 91 | const int dst_depth = AlignByN(IntegralDivideRoundUp(weights.shape.o, 4), 2); |
| 92 | const int src_depth = IntegralDivideRoundUp(weights.shape.i, 4); |
| 93 | |
| 94 | int texture_width = dst_depth; |
| 95 | int texture_height = src_depth * kernel_size_.x * kernel_size_.y; |
| 96 | |
| 97 | DataType data_type = definition_.GetDataType(); |
| 98 | |
| 99 | const int elements_count = texture_width * texture_height; |
| 100 | |
| 101 | if (data_type == DataType::FLOAT32) { |
| 102 | std::vector<float4> gpu_data_0(elements_count); |
| 103 | std::vector<float4> gpu_data_1(elements_count); |
| 104 | std::vector<float4> gpu_data_2(elements_count); |
| 105 | std::vector<float4> gpu_data_3(elements_count); |
| 106 | RearrangeWeightsData(weights, absl::MakeSpan(gpu_data_0), |
| 107 | absl::MakeSpan(gpu_data_1), absl::MakeSpan(gpu_data_2), |
| 108 | absl::MakeSpan(gpu_data_3)); |
| 109 | RETURN_IF_ERROR(CreateTexture2DRGBA(data_type, texture_width, |
| 110 | texture_height, gpu_data_0.data(), |
| 111 | context, &weights_0_)); |
| 112 | RETURN_IF_ERROR(CreateTexture2DRGBA(data_type, texture_width, |
| 113 | texture_height, gpu_data_1.data(), |
| 114 | context, &weights_1_)); |
| 115 | RETURN_IF_ERROR(CreateTexture2DRGBA(data_type, texture_width, |
| 116 | texture_height, gpu_data_2.data(), |
| 117 | context, &weights_2_)); |
| 118 | return CreateTexture2DRGBA(data_type, texture_width, texture_height, |
| 119 | gpu_data_3.data(), context, &weights_3_); |
| 120 | } else { |
| 121 | std::vector<half4> gpu_data_0(elements_count); |
| 122 | std::vector<half4> gpu_data_1(elements_count); |
| 123 | std::vector<half4> gpu_data_2(elements_count); |
| 124 | std::vector<half4> gpu_data_3(elements_count); |
| 125 | RearrangeWeightsData(weights, absl::MakeSpan(gpu_data_0), |
| 126 | absl::MakeSpan(gpu_data_1), absl::MakeSpan(gpu_data_2), |
| 127 | absl::MakeSpan(gpu_data_3)); |
| 128 | RETURN_IF_ERROR(CreateTexture2DRGBA(data_type, texture_width, |
| 129 | texture_height, gpu_data_0.data(), |
| 130 | context, &weights_0_)); |
| 131 | RETURN_IF_ERROR(CreateTexture2DRGBA(data_type, texture_width, |
| 132 | texture_height, gpu_data_1.data(), |
| 133 | context, &weights_1_)); |
| 134 | RETURN_IF_ERROR(CreateTexture2DRGBA(data_type, texture_width, |
| 135 | texture_height, gpu_data_2.data(), |
| 136 | context, &weights_2_)); |
| 137 | return CreateTexture2DRGBA(data_type, texture_width, texture_height, |
| 138 | gpu_data_3.data(), context, &weights_3_); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | template <DataType S, typename T> |
| 143 | void ConvTexture::RearrangeWeightsData( |
nothing calls this directly
no test coverage detected