程序性能调优概要

上传人:今*** 文档编号:108101850 上传时间:2019-10-22 格式:DOC 页数:23 大小:409KB
返回 下载 相关 举报
程序性能调优概要_第1页
第1页 / 共23页
程序性能调优概要_第2页
第2页 / 共23页
程序性能调优概要_第3页
第3页 / 共23页
程序性能调优概要_第4页
第4页 / 共23页
程序性能调优概要_第5页
第5页 / 共23页
点击查看更多>>
资源描述

《程序性能调优概要》由会员分享,可在线阅读,更多相关《程序性能调优概要(23页珍藏版)》请在金锄头文库上搜索。

1、实验题目:程序性能调优实验要求:本次实验,要求针对每个函数、每个人均至少写出3种优化版本、并根据driver报告的结果进行性能分析实验目的: 理解编译器,学习程序优化,从优化程序代码和程序执行速度两方面着手。 实验环境:WIN7 64位、ubuntu ,VMware workstation,实验内容及操作步骤:将下载下来的 kernels.c 中的 rotate、smooth 函数进行优化。 本实验的实验原理是通过循环展开、cache 友好、替换变量等手段来实现程序优化。实验过程及分析:由于优化代码较长,就不进行截图。1. Naive_rotate 1)原代码char naive_rotate

2、_descr = naive_rotate: Naive baseline implementation;void naive_rotate(int dim, pixel *src, pixel *dst) int i, j; for (i = 0; i dim; i+)for (j = 0; j dim; j+) dstRIDX(dim-1-j, i, dim) = srcRIDX(i, j, dim);2)分析 :这段代码的作用就是将所有的像素进行行列调位、导致整幅图画进行了 90 度旋转。P 从 defs.h 中可以找到 #define RIDX(i,j,n) (i)*(n)+(j) 。

3、这段代码本来很短,但是从 cache 友好性来分析,这个代码的效率机会很低, 所以按照 cache 的大小, 应在存储的时候进行 32 个像素依次存储 (列 存储)。做到 cache 友好这样就可以可以大幅度提高效率。#include #include #include defs.hteam_t team = 201308060228, /* 队名 */ 201308060228, /* 序号 */ , /* 邮箱 */ , /* Second member full name (leave blank if none) */ /* Second member email addr (leav

4、e blank if none) */;/* * naive_rotate - The naive baseline version of rotate */char naive_rotate_descr = naive_rotate: Naive baseline implementation;void naive_rotate(int dim, pixel *src, pixel *dst) int i, j; for (i = 0; i dim; i+)for (j = 0; j dim; j+) dstRIDX(dim-1-j, i, dim) = srcRIDX(i, j, dim)

5、;/* * rotate - Your current working version of rotate * IMPORTANT: This is the version you will be graded on */char rotate_descr = rotate: Current working version,using pointer rather than computing address;void rotate(int dim, pixel *src, pixel *dst) int i; int j; int tmp1=dim*dim; int tmp2=dim *31

6、; int tmp3=tmp1-dim; int tmp4=tmp1+32; int tmp5=dim+31; dst+=tmp3; for(i=0; i dim; i+=32) for(j=0;jdim;j+) *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src;

7、dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim;

8、 *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; dst+;src+=dim; *dst=*src; ds

9、t+;src+=dim; *dst=*src; src+; src-=tmp2; dst-=tmp5; src+=tmp2; dst+=tmp4; /* * register_rotate_functions - Register all of your different versions * of the rotate kernel with the driver by calling the * add_rotate_function() for each test function. When you run the * driver program, it will test and

10、 report the performance of each * registered test function. */char rotate_descr_v1 = rotate_v1: version1 break into 4*4 blocks;void rotate_v1(int dim, pixel *src, pixel *dst) int i, j,ii,jj; for(ii=0; ii dim; ii+=4)for(jj=0; jj dim; jj+=4)for(i=ii; i ii+4; i+)for(j=jj; j jj+4; j+) dstRIDX(dim-1-j,i,

11、dim) = srcRIDX(i,j,dim); char rotate_descr_v2 = rotate_v2: version2 break into 32*32 blocks;void rotate_v2(int dim, pixel *src, pixel *dst) int i, j,ii,jj; for(ii=0; ii dim; ii+=32)for(jj=0; jj dim; jj+=32)for(i=ii; i ii+32; i+)for(j=jj; j jj+32; j+) dstRIDX(dim-1-j,i,dim) = srcRIDX(i,j,dim); char rotate_descr_v3 = rotate_v3: version3 break into 4*1 blocks with 4 para

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号