@@ -25,7 +25,9 @@ void add_copy_offset_node(
2525 const ivec3& range,
2626 const ivec4& src_offset,
2727 const ivec4& dst_offset,
28- const ValueRef out) {
28+ const ValueRef out,
29+ bool calc_out_pos_using_src_chnl,
30+ bool calc_in_pos_using_dst_chnl) {
2931 vTensorPtr t_in = graph.get_tensor (in);
3032 vTensorPtr t_out = graph.get_tensor (out);
3133
@@ -49,7 +51,11 @@ void add_copy_offset_node(
4951 // Parameter buffers
5052 {},
5153 // Specialization Constants
52- {graph.hashed_layout_of (out), graph.hashed_layout_of (in)},
54+ {graph.hashed_layout_of (out),
55+ graph.hashed_layout_of (in),
56+ (calc_out_pos_using_src_chnl ? 1
57+ : calc_in_pos_using_dst_chnl ? 2
58+ : 0 )},
5359 nullptr ,
5460 {},
5561 {
@@ -86,19 +92,37 @@ void add_copy_packed_dim_offset_node(
8692 ivec4 final_range = {
8793 range[0 ], range[1 ], range[2 ], dim_at (t_in->sizes (), kBatch4D )};
8894 ivec3 global_wg_size = t_out->logical_limits ();
95+ // The starting offset in a texel where this tensor will start copying from
96+ const auto src_lane_offset = src_offset[packed_dim] & 0x3 ;
8997 // The starting offset in a texel where this tensor will start copying to
9098 const auto dst_lane_offset = dst_offset[packed_dim] & 0x3 ;
99+
100+ // The total packed texels this tensor will be copied from
101+ // The first texel of tensor data in packed dimension will be copied from
102+ // remaining lanes from current source Hence (4 - src_lane_offset) is added
103+ // to tensor size in packed dimension
104+ const auto src_packed_size = utils::div_up_4 (
105+ (4 - src_lane_offset) +
106+ dim_at (t_out->sizes (), normalize_to_dim_index (*t_out, packed_dim)));
107+
91108 // The total packed texels this tensor will be copied to
92- // The first texel of tensor data in packed dimension will be copied to remain
93- // lanes from previous write Hence (4 - dst_lane_offset) is added to tensor
94- // size in packed dimension
109+ // The first texel of tensor data in packed dimension will be copied to
110+ // remaining lanes from previous write Hence (4 - dst_lane_offset) is added to
111+ // tensor size in packed dimension
95112 const auto dst_packed_size = utils::div_up_4 (
96113 (4 - dst_lane_offset) +
97114 dim_at (t_in->sizes (), normalize_to_dim_index (*t_in, packed_dim)));
98115
99- // If the starting offset is not 0, and the total packed texels is greater
116+ // If the starting src offset is not 0, and the total packed texels is greater
117+ // than the source texel range
118+ const bool has_additional_src_work =
119+ src_lane_offset != 0 && src_packed_size > final_range[packed_dim];
120+ // If the starting dst offset is not 0, and the total packed texels is greater
100121 // than the source texel range
101- if (dst_lane_offset != 0 && dst_packed_size > final_range[packed_dim]) {
122+ const bool has_additional_dst_work =
123+ dst_lane_offset != 0 && dst_packed_size > final_range[packed_dim];
124+
125+ if (has_additional_src_work || has_additional_dst_work) {
102126 global_wg_size[packed_dim]++; // Increase the global work group size in
103127 // packed dimension
104128 final_range[packed_dim]++; // Increase the range in packed dimension
@@ -256,7 +280,8 @@ void add_copy_offset_node(
256280 ivec4 src_offset = {src[0 ], src[1 ], src[2 ], 0 };
257281 ivec4 dst_offset = {dst[0 ], dst[1 ], dst[2 ], 0 };
258282
259- add_copy_offset_node (graph, in, range, src_offset, dst_offset, out);
283+ add_copy_offset_node (
284+ graph, in, range, src_offset, dst_offset, out, false , false );
260285}
261286
262287void copy_offset (ComputeGraph& graph, const std::vector<ValueRef>& args) {
0 commit comments