Post

Replies

Boosts

Views

Activity

Comment on Can `MTLTexture` be used to store 5-D input tensor?
Thank you very much for you reply! Firstly, according to step 4 in the guide, the Swift implementation must provide the API endpoints specified in the MLCustomLayer interface. So i guess MPS graph can't be used here? Meanwhile, there is no Declaration introduction in MPS graph. It seems little hard to figure out how to use it. Secondly, id<MTLTexture> in encodeToCommandBuffer is pre-defined. Although Metal supports 3D and 2D array textures, i think we can only use 2D array here, whose pixelFormat = MTLPixelFormatRGBA16Float and depth = 1. I do some tests, the results show that encodeToCommandBuffer can convert the 5-D input to 4-D data automatically. For instance a 5D input data of 16x8x8x32 x32, the converted 4-D data inside the function is width = 32, height = 32, arrayLength=256. However, i'm not fully understand how the convert process happens except the arrayLength seems be calculated by 16x8x8/4. Besides, the grid_sampler function calculation process needs the 5-D input dimension information according to the [official implementation] (https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/cuda/GridSampler.cu). I'm not sure how to used the converted 4-D data inside my kernel since the i don't know the relationship before and after tensor conversion.
Topic: Graphics & Games SubTopic: General Tags:
Jan ’22
Comment on CoreML custom layer implemented by `object-C` doesn't work in `swift` testing project
Yeah, i have checked the name of objective-c class conforming to the MLCustomLayer protocol matches the custom layer name described in the model. It's GridSampleLayer. And i implement the objective-c as shown below, GridSampleLayer.h #import <CoreML/MLCustomLayer.h> #import <Foundation/Foundation.h> #import <CoreML/CoreML.h> @interface GridSampleLayer : NSObject<MLCustomLayer> @end GridSampleLayer.m #import <Foundation/Foundation.h> #import <CoreML/CoreML.h> #import <CoreML/MLMultiArray.h> #import <Vision/Vision.h> #import "GridSampleLayer.h" #import <Accelerate/Accelerate.h> @implementation GridSampleLayer {     } - (BOOL) evaluateOnCPUWithInputs:(NSArray<MLMultiArray *> *)inputs outputs:(NSArray<MLMultiArray *> *)outputs error:(NSError *__autoreleasing _Nullable *)error{ NSLog(@"get in cpu func"); ...... ...... } - (instancetype) initWithParameterDictionary:(NSDictionary<NSString *,id> *)parameters error:(NSError *__autoreleasing _Nullable *)error{   self = [super init];   return self; } - (NSArray<NSArray<NSNumber *> * > *) outputShapesForInputShapes:(NSArray<NSArray<NSNumber *> *> *)inputShapes error:(NSError *__autoreleasing _Nullable *) error{ return inputShapes; } - (BOOL) setWeightData:(NSArray<NSData *> *)weights error:(NSError *__autoreleasing _Nullable *) error{   return true; } @end Are there some problems?
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’22