- 163xxxxx-name
- 163xxxxx-name-report.pdf
- test.sh
- sources
- Makefile
- hw2_cuda.cu
【注意】
- 实验报告一定要转换成PDF形式。
- 以hw*前缀命名的文件,*为作业的次数,每次提交时请修改。
- sources文件夹中的data.bin和cuda_output.txt提交时可以删掉,会生成另外的测试数据
不要删掉all和clean部分
CU_APPS=hw2_cuda
GCC_HOME=/home/jovyan/gcc6/bin/gcc
all: ${CU_APPS}
%: %.cu
nvcc -o $@ $<
clean:
rm -f ${CU_APPS}
-
输入:data.bin(数据文件), s(卷积核大小)
-
输出:h(高), w(宽), out_array(卷积后的数组)
注意不要输出任何除了h, w, out_array以外的数据
-
核函数命名:kernel
输入输出样例
# 输入
# data.bin为二进制文件,分别输入h, w, in_array
./hw2_cuda data.bin 2
# 输出(设输出为5x5的全0二维数组,数据之间用空格分隔,注意高和宽后面接换行符'\n')
5 5
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
读取data.bin二进制文件具体细节 测试时会有另外的data.bin文件,请勿修改读取文件部分的操作
int height, width;
float data[MAX_BUFFER];
FILE *fp;
fp = fopen(argv[1], "rb");
fread(&height, sizeof(height), 1, fp);
fread(&width, sizeof(width), 1, fp);
fread(data, sizeof(float), height*width, fp);
fclose(fp);
程序输出具体细节
printf("%d %d\n",height,width);
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
printf("%.02f ",result[i*width+j]);
}
}
# 压缩
tar zcvf 163xxxxx-name.tar.gz 163xxxxx-name
# 解压
tar zxvf 163xxxxx-name.tar.gz
将test.sh放入163xxxxx-name
目录下,在集群中测试通过后才可提交。
cd 163xxxxx-name
chmod +x ./test.sh
./test.sh
# 输出结果不能有“>>>>>>>>>> failed <<<<<<<<<<”
- 测试脚本test.sh
#!/bin/bash
function test_cmd()
{
if [ $? -ne 0 ];then
echo -e "\n>>>>>>>>>> failed: \"$1\" <<<<<<<<<<\n"
else
echo -e "\n>>>>>>>>>> succeed: \"$1\" <<<<<<<<<<\n"
fi
}
# cd sources
cd ./sources
test_cmd "cd ./sources";
# make
make clean
test_cmd "make clean";
make all
test_cmd "make all";
# run program
echo 'data.bin 2' | ./hw2_cuda data.bin 2 > cuda_output.txt
test_cmd "echo 'data.bin 2' | ./hw2_cuda data.bin 2 > cuda_output.txt";
# test tar
cd ../
dir_name=$(echo ${PWD##*/})
cd ../
cp -r $dir_name "$dir_name"_test
if [ $dir_name != "jovyan" -o $dir_name != "home" ];then
tar zcvf "$dir_name"_test.tar.gz "$dir_name"_test
test_cmd "tar zcvf \"$dir_name\"_test.tar.gz \"$dir_name\"_test";
tar zxvf "$dir_name"_test.tar.gz
test_cmd "tar zxvf \"$dir_name\"_test.tar.gz";
rm -rf "$dir_name"_test
rm "$dir_name"_test.tar.gz
fi
- 正确的测试输出
jovyan@jupyter-TA:~/163xxxxx-name$ ./test.sh
>>>>>>>>>> succeed: "cd ./sources" <<<<<<<<<<
rm -f hw2_cuda
>>>>>>>>>> succeed: "make clean" <<<<<<<<<<
nvcc -o hw2_cuda hw2_cuda.cu
>>>>>>>>>> succeed: "make all" <<<<<<<<<<
>>>>>>>>>> succeed: "echo 'data.bin 2' | ./hw2_cuda data.bin 2 > cuda_output.txt" <<<<<<<<<<
163xxxxx-name_test/
163xxxxx-name_test/sources/
163xxxxx-name_test/sources/hw2_cuda
163xxxxx-name_test/sources/cuda_output.txt
163xxxxx-name_test/sources/hw2_cuda.cu
163xxxxx-name_test/sources/Makefile
163xxxxx-name_test/sources/.ipynb_checkpoints/
163xxxxx-name_test/test.sh
163xxxxx-name_test/.ipynb_checkpoints/
>>>>>>>>>> succeed: "tar zcvf "163xxxxx-name"_test.tar.gz "163xxxxx-name"_test" <<<<<<<<<<
163xxxxx-name_test/
163xxxxx-name_test/sources/
163xxxxx-name_test/sources/hw2_cuda
163xxxxx-name_test/sources/cuda_output.txt
163xxxxx-name_test/sources/hw2_cuda.cu
163xxxxx-name_test/sources/Makefile
163xxxxx-name_test/sources/.ipynb_checkpoints/
163xxxxx-name_test/test.sh
>>>>>>>>>> succeed: "tar zxvf "163xxxxx-name"_test.tar.gz" <<<<<<<<<<