




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/* * Kernels to be optimized for the CS:APP Performance Lab */#include #include #include defs.h/* * Please fill in the following team struct */team_t team = 5120379091, /* Student ID */ Gao Ce, /* Your Name */ , /* First member email address */ , /* Second member full name (leave blank if none) */ /* Second member email addr (leave blank if none) */;/* * ROTATE KERNEL */* * Your different versions of the rotate kernel go here */* *Add the description of your Rotate implementation here! *1. Brief Intro of method *2. CPE Achieved *3. other words */* * 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);/* * rotate - Your current working version of rotate * IMPORTANT: This is the version you will be graded on */char rotate_descr = rotate: Current working version;void rotate(int dim, pixel *src, pixel *dst) int i, j; dst += (dim-1)*dim; for (i = 0; i dim; i+=32) for (j = 0; j dim; j+) *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+=dim; dst+=1; *dst=*src; src+; src -= (dim5)-dim; dst-=31+dim; dst+=dim*dim; dst+=32; src += (dim5)-dim; /* * 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 report the performance of each * registered test function. */void register_rotate_functions() add_rotate_function(&naive_rotate, naive_rotate_descr); add_rotate_function(&rotate, rotate_descr); /* . Register additional test functions here */* * SMOOTH KERNEL */* *Add description of your Smooth Implementation here! *1. Brief Intro of your method *2. CPE Achieved *3. Any other. */* * Various typedefs and helper functions for the smooth function * You may modify these any way you like. */* A struct used to compute averaged pixel value */typedef struct int red; int green; int blue; int num; pixel_sum;typedef struct int red; int green; int blue; pixel_int;/* Compute min and max of two integers, respectively */static int min(int a, int b) return (a b ? a : b); /* * initialize_pixel_sum - Initializes all fields of sum to 0 */static void initialize_pixel_sum(pixel_sum *sum) sum-red = sum-green = sum-blue = 0; sum-num = 0; return;/* * accumulate_sum - Accumulates field values of p in corresponding * fields of sum */static void accumulate_sum(pixel_sum *sum, pixel p) sum-red += (int) p.red; sum-green += (int) p.green; sum-blue += (int) p.blue; sum-num+; return;/* * assign_sum_to_pixel - Computes averaged pixel value in current_pixel */static void assign_sum_to_pixel(pixel *current_pixel, pixel_sum sum) current_pixel-red = (unsigned short) (sum.red/sum.num); current_pixel-green = (unsigned short) (sum.green/sum.num); current_pixel-blue = (unsigned short) (sum.blue/sum.num); return;/* * avg - Returns averaged pixel value at (i,j) */static pixel avg(int dim, int i, int j, pixel *src) int ii, jj; pixel_sum sum; pixel current_pixel; initialize_pixel_sum(&sum); for(ii = max(i-1, 0); ii = min(i+1, dim-1); ii+) for(jj = max(j-1, 0); jj = min(j+1, dim-1); jj+) accumulate_sum(&sum, srcRIDX(ii, jj, dim); assign_sum_to_pixel(¤t_pixel, sum); return current_pixel;/* * Your different versions of the smooth kernel go here */* * naive_smooth - The naive baseline version of smooth */char naive_smooth_descr = naive_smooth: Naive baseline implementation;void naive_smooth(int dim, pixel *src, pixel *dst) int i, j; for (i = 0; i dim; i+) for (j = 0; j 2; dst0.blue = (src0.blue+src1.blue+srcdim.blue+srcdim+1.blue)2; dst0.green = (src0.green+src1.green+srcdim.green+srcdim+1.green)2; dstdim-1.red = (srcdim-1.red+srcdim-2.red+srcdim*2-1.red+srcdim*2-2.red)2; dstdim-1.blue = (srcdim-1.blue+srcdim-2.blue+srcdim*2-1.blue+srcdim*2-2.blue)2; dstdim-1.green = (srcdim-1.green+srcdim-2.green+srcdim*2-1.green+srcdim*2-2.green)2; dstdim*(dim-1).red = (srcdim*(dim-1).red+srcdim*(dim-1)+1.red+srcdim*(dim-2).red+srcdim*(dim-2)+1.red)2; dstdim*(dim-1).blue = (srcdim*(dim-1).blue+srcdim*(dim-1)+1.blue+srcdim*(dim-2).blue+srcdim*(dim-2)+1.blue)2; dstdim*(dim-1).green = (srcdim*(dim-1).green+srcdim*(dim-1)+1.green+srcdim*(dim-2).green+srcdim*(dim-2)+1.green)2; dstdim*dim-1.red = (srcdim*dim-1.red+srcdim*dim-2.red+srcdim*(dim-1)-1.red+srcdim*(dim-1)-2.red)2; dstdim*dim-1.blue = (srcdim*dim-1.blue+srcdim*dim-2.blue+srcdim*(dim-1)-1.blue+srcdim*(dim-1)-2.blue)2; dstdim*dim-1.green = (srcdim*dim-1.green+srcdim*dim-2.green+srcdim*(dim-1)-1.green+srcdim*(dim-1)-2.green)2; for (j = 1; j dim-1; j+) dstj.red = (srcj.red+srcj-1.red+srcj+1.red+srcj+dim.red+srcj+1+dim.red+srcj-1+dim.red)/6; dstj.green = (srcj.green+srcj-1.green+srcj+1.green+srcj+dim.green+srcj+1+dim.green+srcj-1+dim.green)/6; dstj.blue = (srcj.blue+srcj-1.blue+srcj+1.blue+srcj+dim.blue+srcj+1+dim.blue+srcj-1+dim.blue)/6; for (j = dim*(dim-1)+1; j dim*dim-1; j+) dstj.red = (srcj.red+srcj-1.red+srcj+1.red+srcj-dim.red+srcj+1-dim.red+srcj-1-dim.red)/6; dstj.green = (srcj.green+srcj-1.green+srcj+1.green+srcj-dim.green+srcj+1-dim.green+srcj-1-dim.green)/6; dstj.blue = (srcj.blue+srcj-1.blue+srcj+1.blue+srcj-dim.blue+srcj+1-dim.blue+srcj-1-dim.blue)/6; for (j = dim; j dim*(dim-1); j+=dim) dstj.red = (srcj.red+srcj-dim.red+srcj+1.red+srcj+dim.red+srcj+1+dim.red+srcj-dim+1.red)/6; dstj.green = (srcj.green+srcj-dim.green+srcj+1.green+srcj+dim.green+srcj+1+dim.green+srcj-dim+1.green)/6; dstj.blue = (srcj.blue+srcj-dim.blue+srcj+1.blue+srcj+dim.blue+srcj+1+dim.blue+srcj-dim+1.blue)/6; for (j = dim+dim-1; j dim*dim-1; j+=dim) dstj.red = (srcj.red+srcj-1.red+srcj-dim.red+srcj+dim.red+srcj-dim-1.red+srcj-1+dim.red)/6; dstj.green = (srcj.green+srcj-1.green+srcj-dim.green+srcj+dim.green+srcj-dim-1.green+srcj-1+dim.green)/6; dstj.blue = (srcj.blue+srcj-1.blue+srcj-dim.blue+srcj+dim.blue+srcj-dim-1.blue+srcj-1+dim.blue)/6; for (i = 1; i dim-1; i+) for (j = 1; j dim-1; j+) rij = rindex+j; dstrij.red = (srcrij.red+srcrij-1.red+srcrij+1.red+srcrij-dim.red+srcrij-dim-1.red+srcrij-dim+1.red+srcrij+dim.red+srcrij+dim+1.red+srcrij+dim-1.red)/9; dstrij.green = (srcrij.green+
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026届广东省北京师范大学东莞石竹附属学校化学高一第一学期期末检测试题含解析
- 2026届山西省太原市小店区一中高一化学第一学期期中达标测试试题含解析
- 2025年潜水安全知识考试题库
- 火力发电厂教学课件
- 2025年5G行业销售客服岗位招聘考试题
- 2026届安徽省肥东县高级中学化学高一上期末复习检测模拟试题含解析
- 灌溉农业知识培训总结
- 知识地图拆卸培训课件
- 知识及技能培训课件
- 虚拟音乐表演系统-洞察及研究
- 在线教育行业智能学习与个性化教育方案
- 工程变更流程ECN
- LED电子显示屏系统设计方案
- 高中英语人教新教材选择性必修一全册词汇表和默写表(分单元编排)
- 矿床学全套教学课件
- HG-T 6038-2022 聚乙烯蜡微粉
- 全册(教案)人教精通版英语五年级下册
- 2024年山东高速投资控股限公司校园招聘9人重点基础提升难、易点模拟试题(共500题)附带答案详解
- 中石油吊装安全经验分享
- 法院结案书样本合集3篇
- 游标卡尺使用培训课件
评论
0/150
提交评论