Onednn: Understanding strided memory

Created on 8 Mar 2021  路  4Comments  路  Source: oneapi-src/oneDNN

Hi, I'm trying to use strided memory with strides of zero as shown here, however, I'm not seeing the results I expect.

In particular:

  1. I expect strides {3,0} in my example to read only the 0th and the 3rd elements from my data array (resulting in a tensor of [[1 1 1][4 4 4]]). Instead, the entire data array is being read (resulting in a tensor of [[1 2 3][4 5 6]]). Strides of {0,1} and {0,0} work as expected, though.
  2. I expect strides containing a zero to work for both the left and right arguments, but they are only working in the right argument. When I include a zero in the strides of the left memory descriptor, I get "could not create a descriptor for a binary operation primitive."

Have I gotten something wrong here, or if not how can I make sense of the above? Thank you.

bug question

All 4 comments

Hi @alannnna ,
Thank you for your report. I reproduced behavior you described. It is an issue in optimized version of binary primitive, I tried your reproducer with manually disabled optimized implementation and the result matches expected result:
The current behavior on master:

DNNL_VERBOSE=1 ./build/examples/zero-strides-cpp
dnnl_verbose,info,cpu,runtime:OpenMP
dnnl_verbose,info,cpu,isa:Intel AVX2
dnnl_verbose,info,gpu,runtime:none
dnnl_verbose,info,prim_template:operation,engine,primitive,implementation,prop_kind,memory_descriptors,attributes,auxiliary,problem_desc,exec_time
dnnl_verbose,exec,cpu,binary,jit:uni,undef,src_f32::blocked:ab:f0 src_f32::blocked:ab:f0 dst_f32::blocked:ab:f0,,alg:binary_add,2x3:2x3,2.04419
1 2 3 4 5 6

With disabled optimized implementation:

dnnl_verbose,info,cpu,runtime:OpenMP
dnnl_verbose,info,cpu,isa:Intel AVX2
dnnl_verbose,info,gpu,runtime:none
dnnl_verbose,info,prim_template:operation,engine,primitive,implementation,prop_kind,memory_descriptors,attributes,auxiliary,problem_desc,exec_time
dnnl_verbose,exec,cpu,binary,ref:any,undef,src_f32::blocked:ab:f0 src_f32::blocked:ab:f0 dst_f32::blocked:ab:f0,,alg:binary_add,2x3:2x3,5.67798
1 1 1 4 4 4

As a short-term solution you could disable jit implementations by commenting out jit_uni_*_binary instantiations in src/cpu/cpu_binary_list.cpp, however performance will be affected for all binary operations used in your application. In long - term jit binary should either support such memory descriptors or be disabled for those cases.
We will update you once fix is promoted in master.

Regards,
Igor Safonov

Hi @alannnna ,
Could you please post the example on your side under Apache license so we can include it in oneDNN repository as a regression test?

Regards,
Igor Safonov

@igorsafo - I added a LICENSE file to the gist. Let me know if I should do something different. Thanks!

Fixed by 5906f4d003d5ac225d62afa092473107c2b3713e and backported to v2.2.

Was this page helpful?
0 / 5 - 0 ratings