设置stride

一个height*width的buffer,按照列方向取数,为了避免bank冲突,需要设置合适的stride_w

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

void find_w(int width)
{
	int height = 1024;
	int tile_h = 16;
	int tile_nums = (height + tile_h - 1) / tile_h;
	int last_tile_h = height - (tile_nums - 1) * tile_h;

	int is_ok = 1;
	int flag[16];
	for (int x = 0; x < width; x++)
	{
		for (int i = 0; i < tile_nums; i++)
		{
			int cur_h = (i == (tile_nums - 1)) ? last_tile_h : tile_h;
			memset(flag, 0, 16 * sizeof(int));
			for (int y = (i * tile_h); y < (i * tile_h + cur_h); y++)
			{
				int index = y * width + x;
				int mod = index % 128;
				int bank = mod / 8;
				//printf("%d,  ", bank);
				if (flag[bank])
				{
					return;
				}
				else
				{
					flag[bank] = 1;
				}
			}
		}
		//printf("\n");
	}
	if (is_ok)
	{
		printf("width=%d\n", width);
	}
}

int main()
{
	for (int w = 1; w < 1000; w++)
	{
		find_w(w);
	}
	return 0;
}

经过上述代码寻找,得到如下stride

width=8
width=24
width=40
width=56
width=72
width=88
width=104
width=120
width=136

总结为:y=16*x+8,其中x为整数

即:stride_w =  half_up_round((width - 8) / 16) * 16 + 8

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值