oneapi-src / oneDNN

oneAPI Deep Neural Network Library (oneDNN)
https://uxlfoundation.org
Apache License 2.0
3.59k stars 990 forks source link

Where is the core logic of Convolution2D code? #953

Closed sliawatimena closed 3 years ago

sliawatimena commented 3 years ago

Dear all,

Would you mind to shed a light where is the core logic of Convlution2D code? Thank you very much in advance.

Warmest Regards, Suryadi

dzarukin commented 3 years ago

Hi @sliawatimena, thank you for the question.

Could you shed a light, please, what do you put in "core logic"? Do you have something specific on your mind?

For starters you may inspect convolution example which covers the API essentials and reference forward convolution implementation to see the operation logic and supported features in non-optimized code. Also, there's a nice convolution dev guide page. If this doesn't cover the specifics of your question, please let me know. Thanks.

LiuXiaoxuanPKU commented 3 years ago

What's the relationship between reference forward convolution implementation (ref_convolution.cpp) and gemm_convolution.cpp/gemm_x8s8s32x_convolution.cpp?

dzarukin commented 3 years ago

Hi @LiuXiaoxuanPKU, that's a good question.

Each primitive has a list of implementations, each of them performs the same operation leading to the same result but with different feature coverage and speed (performance). Their mutual relationship maybe found at list file. Lists are separated in data types and are prioritized. The primitive tries to pick up an implementation from top to bottom. The library tries to prioritize them from most performant to least performant (which is reference code). Thanks.

sliawatimena commented 3 years ago

Hi @sliawatimena, thank you for the question.

Could you shed a light, please, what do you put in "core logic"? Do you have something specific on your mind?

For starters you may inspect convolution example which covers the API essentials and reference forward convolution implementation to see the operation logic and supported features in non-optimized code. Also, there's a nice convolution dev guide page. If this doesn't cover the specifics of your question, please let me know. Thanks.

I read convolution example and did not find what I need.

I need to see something like picture below: image

I want to learn how to create my own Convolution4d based on Convolution2D c++ code. Is that possible? Thank you very much in advance.

dzarukin commented 3 years ago

Hi @sliawatimena, I'm confused. Are you asking how to write personal simple convolution kernel on C++?

sliawatimena commented 3 years ago

I am a Doctor of Computer Science of Bina Nusantara University, Indonesia. My research needs to create a new operator called Conv4D. I have learned conv2d from MindSpore 1.1 for CPU. I find it calls OneDNN, using memory pointers. image Is it possible that I get inside / behind the Conv2D in OneDNN, clone it into Conv4d, then change it to my own Conv4D logic?

Thank you very much in advance.

vpirogov commented 3 years ago

@sliawatimena,

You could probably extend oneDNN convolution implementation to support 4D spatial domain (that what I expect Conv4D stands for). The code though has platform specific optimizations and you'll need experience with assembly language programming to extend the optimized implementation.

I would suggest that you start with convolution reference imlementation that @dzarukin linked above. This code implements convolution for 3D spatial domain and should be relatively straightforward to extend to 4D.

sliawatimena commented 3 years ago

@vpirogov, How do I start to register my new operator called Conv4D so the program caller can import and use it? The Conv4d input and output parameters are the same as the Conv2D, but the Conv4D logic I will try to modify from Conv2D.

If I want to git clone OneDNN to my local computer, how do I compile it using my Intel x86_64 processor inside my Ubuntu 18.04, Python 3.7.5 and gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

Thank you very much.

vpirogov commented 3 years ago

You can find instructions on building oneDNN from source in the Developer Guide.

There's no need to introduce new operator to support 4D spatial convolutions. You need to extend the implementation I pointed you to with support for an additional dimension.

vpirogov commented 3 years ago

Closing as the question seems to be addressed. Feel free to reopen or submit a new one with additional data.