如何计算平均缓存未命中率(ACMR)?

如何计算平均缓存未命中率(ACMR)?,c,caching,optimization,vertex,C,Caching,Optimization,Vertex,我正在研究Tom Forsyth的线性速度顶点缓存优化,我不明白他是如何计算ACMR的。从我所读到的内容中,我已经知道ACMR=缓存未命中数/三角形数,但我不知道使用的是哪种缓存(即FIFO或LRU?) 我已经编写了一个测试程序,使用FIFO缓存计算并打印给定3d模型的ACMR,你能告诉我这个代码是否正确吗?还是应该使用LRU缓存 /* the number of entries in a FIFO cache */ #define FIFO_CACHE_SIZE 32 struct

我正在研究Tom Forsyth的线性速度顶点缓存优化,我不明白他是如何计算ACMR的。从我所读到的内容中,我已经知道ACMR=缓存未命中数/三角形数,但我不知道使用的是哪种缓存(即FIFO或LRU?)

我已经编写了一个测试程序,使用FIFO缓存计算并打印给定3d模型的ACMR,你能告诉我这个代码是否正确吗?还是应该使用LRU缓存

/* the number of entries in a FIFO cache */
#define FIFO_CACHE_SIZE     32

struct fifo_cache {
    long entries[FIFO_CACHE_SIZE];
};

/**
 * init_cache - initializes a FIFO cache
 * @cache: A pointer to the FIFO cache structure to be initialized.
 *
 * Before a FIFO cache can be used, it must be initialized by calling this
 * function.
 */
static void init_cache(struct fifo_cache *cache)
{
    int i = 0;

    /* initialize cache entries to an invalid value */
    for (i = 0;i < FIFO_CACHE_SIZE;i++)
        cache->entries[i] = -1;
}

/**
 * check_entry - checks if the same entry is already added to the cache
 * @cache: A pointer to the FIFO cache structure to be searched.
 * @entry: An entry to be searched for.
 *
 * Return: If the same entry was found, the return value is nonzero. Otherwise,
 *         the return value is zero.
 */
static int check_entry(const struct fifo_cache *cache, u16 entry)
{
    int i = 0;

    for (i = 0;i < FIFO_CACHE_SIZE;i++) {
        if (cache->entries[i] == (long)entry)
            return 1;
    }

    return 0;
}

/**
 * add_entry - adds a new entry to the FIFO cache
 * @cache: A pointer to the FIFO cache structure the entry will be added to.
 * @entry: An entry to add.
 */
static void add_entry(struct fifo_cache *cache, u16 entry)
{
    long aux = 0;
    long aux2 = 0;
    int i = 0;

    aux = cache->entries[0];
    cache->entries[0] = (long)entry;

    for (i = 1;i < FIFO_CACHE_SIZE;i++) {
        aux2 = cache->entries[i];
        cache->entries[i] = aux;
        aux = aux2;
    }
}

/**
 * calculate_acmr - calculates the average cache miss ratio (aka. ACMR)
 * @indices: The list of vertex indices.
 * @count: The number of vertex indices in the @indices list.
 */
float calculate_acmr(const u16 *indices, size_t count)
{
    struct fifo_cache cache = {0};
    long total = 0; /* the total number of cache misses */
    long i = 0;

    /* initialize the cache */
    init_cache(&cache);

    for (i = 0;i < count;i++) {
        if (!check_entry(&cache, indices[i])) {
            /* an entry doesn't exist in the cache, so add it */
            add_entry(&cache, indices[i]);

            total++;
        }
    }

    return ((float)total / (count / 3));
}
/*FIFO缓存中的条目数*/
#定义FIFO_缓存_大小32
结构fifo_缓存{
长条目[FIFO_缓存_大小];
};
/**
*初始化FIFO缓存-初始化FIFO缓存
*@cache:指向要初始化的FIFO缓存结构的指针。
*
*在使用FIFO缓存之前,必须通过调用
*功能。
*/
静态void init_缓存(结构fifo_缓存*缓存)
{
int i=0;
/*将缓存项初始化为无效值*/
对于(i=0;i条目[i]=-1;
}
/**
*检查\u条目-检查是否已将相同条目添加到缓存中
*@cache:指向要搜索的FIFO缓存结构的指针。
*@entry:要搜索的条目。
*
*Return:如果找到相同的条目,则返回值为非零。否则,,
*返回值为零。
*/
静态整数检查项(常量结构fifo缓存*缓存,u16项)
{
int i=0;
对于(i=0;i条目[i]==(长)条目)
返回1;
}
返回0;
}
/**
*add_entry-将新条目添加到FIFO缓存中
*@cache:指向条目将添加到的FIFO缓存结构的指针。
*@entry:要添加的条目。
*/
静态无效添加项(结构fifo缓存*缓存,u16项)
{
长aux=0;
长aux2=0;
int i=0;
aux=缓存->条目[0];
缓存->条目[0]=(长)条目;
对于(i=1;i条目[i];
缓存->条目[i]=aux;
aux=aux2;
}
}
/**
*计算\ acmr-计算平均缓存未命中率(aka.acmr)
*@index:顶点索引列表。
*@count:@index列表中的顶点索引数。
*/
浮点计算acmr(常数u16*指数、大小计数)
{
结构fifo_缓存={0};
long total=0;/*缓存未命中的总数*/
长i=0;
/*初始化缓存*/
初始化缓存(&cache);
对于(i=0;i
我找到了答案。现代GPU使用FIFO缓存以实现简单性和速度,因此使用FIFO缓存计算ACMR是有意义的。上面给出的代码是正确的,所以我将继续使用它。

您是正确的,硬件就是这样做的。此外,您可能需要阅读以下内容: