Skip to content

Process grid tensor by builder.add_transpose makes the function always run on CPU #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Tengxu-Sun opened this issue Jan 20, 2022 · 4 comments

Comments

@Tengxu-Sun
Copy link

Tengxu-Sun commented Jan 20, 2022

Hi, @dneprDroid
I'm trying to implement a 5-D input tensor version of custom grid_sample based on your work. Now i meet two problems hoping you can help me.
First, you said "we should transpose the grid to [n, 2, w, h] shape (for encoding it to a coreml 2-channel texture)". But i found this process may lead to the function always run on CPU in my implementation. The GPU function encode works without this process. I read your code but haven't find a solution. Have you met this problem ever?

Second, since i want implement a 5-D input tensor version of custom grid_sample, how id<MTLTexture> in encode work at this time? I found the data storage is different with ordinary buffer, and i'm not sure how to read data in id<MTLTexture> so that the data can be calculated in later computation process.
Thank you!

@dneprDroid
Copy link
Owner

dneprDroid commented Jan 22, 2022

Hi,

  1. The case without transpose you can find on this branch fix/without-transpose

  2. The case with 5-D input is complicated, not sure about that. You can try to rewrite the shader with texturecube_array input instead of texture2d_array and your grid vector may contain 3 coordinates (grid_X, grid_Y, grid_Z).

@Tengxu-Sun
Copy link
Author

Tengxu-Sun commented Jan 22, 2022

Hi,

  1. The case without transpose you can find on this branch fix/without-transpose
  2. The case with 5-D input is complicated, not sure about that. You can try to rewrite the shader with texturecube_array input instead of texture2d_array and your grid vector may contain 3 coordinates (grid_X, grid_Y, grid_Z).

Thanks for your reply!

  1. Cool, i'll see it carefully later.
  2. According to guide, MTLTextureTypeCube is a cube texture with six two-dimensional images. I'm not sure weather texturecube_array is suitable for 5-D input since it seems still can't store the contiguous depth of the feature. Meanwhile, i do some tests to print the information of [MTLTexture] in [encode function]. The result shows that its default textureType = MTLTextureType2DArray and seems can't be changed manually. So i guess textureType in Metal shader also need to be texture2d_array. Do you have any suggestions to change the textureType of [MTLTexture] in encode function? Thanks again.

@Tengxu-Sun
Copy link
Author

Hi,

  1. The case without transpose you can find on this branch fix/without-transpose
  2. The case with 5-D input is complicated, not sure about that. You can try to rewrite the shader with texturecube_array input instead of texture2d_array and your grid vector may contain 3 coordinates (grid_X, grid_Y, grid_Z).
  1. Update: I test the without transpose branch on Iphone11, and find it not totally equal. The original implementation looks more delicate, while it looks rougher after the change. Please have a look in you spare time, Thanks a lot!

@nighting0le01
Copy link

hi @Tengxu-Sun were you able to get the 5d torch.grid_sampler to work in coreml??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants