oneDNN icon indicating copy to clipboard operation
oneDNN copied to clipboard

what is the role of sync_before_read function?

Open haidj opened this issue 9 years ago • 6 comments

Hello,

I confirmed that the following function takes up a large part of the execution time during backward convolution. bwdd_top_diff->sync_before_read();

If you follow the code, simple memory copy occurs as shown below. However, it seems that the process of obtaining the offset is complicated and takes a long time.

for (size_t e = 0; e < nelems; ++e) { output[output_d.off_l(e)] = data_t<type_o>(input[input_d.off_l(e)]);

In this situation, I want to know exactly what this code is doing and whether it is necessary code in a single node environment.

Thank you. Daejin Jung.

haidj avatar May 26 '17 14:05 haidj

In addition, I found the following issue.

set_prv_data_descriptor call twice with different parameters in mkldnn_memory.cpp blob->set_prv_data_descriptor(this->get_shared_ptr(), false); . blob->set_prv_data_descriptor(NULL); please see 251-254 line

If set_prv_data_descriptor (NULL) is commented out, the processing speed of bwdd_top_diff-> sync_before_read () is improved in backward convolution.

But, I wonder if this will give a reasonable result.

Thank you Daejin Jung

haidj avatar May 26 '17 16:05 haidj

Hi @HAIDJ,

MKL-DNN supports variety of data layouts (like NCHW, CHWN, NHWC, etc...), listed in mkldnn_memory_format_t enum. In order to traverse memory with different layouts we have very general offset function that computes physical offset by given logical one (impl is here). But the implementation is really slow due to the generality. All the optimized primitives don't use it, since they can work only on a subset of memory layouts, hence may compute offsets themselves.

So the answer on the second part of your first question:

... I want to know exactly what this code is doing and whether it is necessary code in a single node environment

is yes, the code is absolutely to produce correct results.

The fact you observe this code in your case most likely means MKL-DNN falls back to some default (read unoptimized) implementation. What platform do you use? What is the topology? And which layer behaves bad?

If set_prv_data_descriptor (NULL) is commented out, the processing speed of bwdd_top_diff-> sync_before_read () is improved in backward convolution.

But, I wonder if this will give a reasonable result.

It makes sense to discuss this part on IntelCaffe forum since IntelCaffe team makes MKL-DNN integration to the framework. At least I don't recall what is the specific purpose of this code... :( But assume if you comment it out IntelCaffe may produce incorrect results.

emfomenk avatar May 26 '17 17:05 emfomenk

Hello, emfomenk Thank you for your reply. But, I have additional questions.

All the optimized primitives don't use it, since they can work only on a subset of memory layouts, hence may compute offsets themselves.

How can I apply the optimized primitives you mentioned? I used xeon-phi 7250 CPU with my modified prototxt based on mkl2017-resnet_50.

In my case, execution time of backward convolution is quite slow because of following line to copy bwdd_weights_data. bwdd_weights_data->sync_before_read();

For example, the bwd convolution time is considerably longer than the fwd convolution time, and most of them are time for copying weights.

-- Please take a look at an example of run time per layer below. (c.f., I used resnet-50 with 64 batch.) FW_res5c_branch2c layer: 0.0035 sec BWD_res5c_branch2c layer: 0.0090 sec bwdd_bottom_diff->sync_before_write();: 0.0006 sec bwdd_weights_data->sync_before_read();: 0.0070 sec
At this point, I'd like apply the optimized primitive to improve backward convolution time. convBwdData.submit();: 0.00003

Another strange part is that the execution time is fairly small for actual backward convolution using a 1x1 filter. Checking with the performance tool shows that the number of floating point operations processed is pretty smaller than expected.

Could you give me a comment about it?

Thank you. Daejin Jung

haidj avatar May 28 '17 09:05 haidj

How can I apply the optimized primitives you mentioned? I used xeon-phi 7250 CPU with my modified prototxt based on mkl2017-resnet_50.

IntelCaffe uses optimized automatically primitives whenever possible. It does that by creating certain MKL-DNN primitives like convolutions with parameters that instruct the library to pick the best formats for the given input parameters. I'll ask someone from IntelCaffe team to look at this issue.

rsdubtso avatar May 31 '17 06:05 rsdubtso

Hi @HAIDJ,

I see you have performance results for MKL2017 and MKLDNN engines for your ResNet-based topology. Results for MKLDNN are much worse because IntelCaffe does a lot of unnecessary layout conversions. This will be addressed in the upcoming update of IntelCaffe.

vpirogov avatar Jun 01 '17 00:06 vpirogov

Look like the latest IntelCaffe version has the issue with conversions addressed.

vpirogov avatar Jun 19 '17 16:06 vpirogov