1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_LITE_DELEGATES_GPU_METAL_BUFFER_CONVERT_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_METAL_BUFFER_CONVERT_H_ 18 19 #import <Metal/Metal.h> 20 21 #include "tensorflow/lite/delegates/gpu/common/shape.h" 22 23 @interface TFLBufferConvert : NSObject 24 25 /// Constructs converter from/to BHWC <-> BPHWC4 26 /// @param isFloat16 the BPHWC4 buffer is in float16 format. 27 /// @param convertToPBHWC4 convert BHWC -> BPHWC4 if true or BPHWC4 -> BHWC instead. 28 - (id)initWithDevice:(id<MTLDevice>)device 29 isFloat16:(bool)isFloat16 30 convertToPBHWC4:(bool)convertToPBHWC4; 31 32 /// Converts from/to BHWC <-> BPHWC4 33 /// @param shape shape of BHWC tensor. 34 - (void)convertWithEncoder:(id<MTLComputeCommandEncoder>)encoder 35 shape:(const ::tflite::gpu::BHWC&)shape 36 sourceBuffer:(id<MTLBuffer>)sourceBuffer 37 convertedBuffer:(id<MTLBuffer>)convertedBuffer; 38 39 @end 40 41 #endif // TENSORFLOW_LITE_DELEGATES_GPU_METAL_BUFFER_CONVERT_H_ 42