<file_sep>loopNum=100
scaleNum=8
devID=1

#Test1
baseHA=32
baseHB=32
baseW=32
c=0 #compare, no need to compare
	for((scale=1; scale < $scaleNum; scale++))
	do
		scaler=$((1))
		for((cnt=0; cnt < scale; cnt ++))
		do
			scaler=$(($scaler*2))
		done
		hA=$(($baseHA*$scaler))
		hB=$(($baseHB*$scaler))
		W=$(($baseW*$scaler))
		for((i=0; i < $loopNum; i++))
		do
			echo
			echo "Test1 ======= ($i): devID=$devID, hA=$hA, hB=$hB, W=$W======="
			echo "-------> No transpose"
			./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=0 -compare=0
			./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=0 -compare=0 >> test_devID_$devID\_hA_$hA\_hB_$hB\_W_$W\_transpose_0\.log
			echo
			echo "-------> Transpose"
			./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=1 -compare=0
			./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=1 -compare=0 >> test_devID_$devID\_hA_$hA\_hB_$hB\_W_$W\_transpose_1\.log
		done
	done


#Test2
baseHA=64
baseHB=64
baseW=8
c=0 #compare, no need to compare

	for((scale=1; scale < $scaleNum; scale++))
	do
		scaler=$((1))
		for((cnt=0; cnt < scale; cnt ++))
		do
			scaler=$(($scaler*2))
		done
		hA=$(($baseHA*$scaler))
		hB=$(($baseHB*$scaler))
		W=$(($baseW*$scaler))
		for((i=0; i < $loopNum; i++))
		do
			echo
			echo "Test2 ======= ($i): devID=$devID, hA=$hA, hB=$hB, W=$W======="
			echo "-------> No transpose"
			./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=0 -compare=0
			./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=0 -compare=0 >> test_devID_$devID\_hA_$hA\_hB_$hB\_W_$W\_transpose_0\.log
			echo
			echo "-------> Transpose"
			./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=1 -compare=0
			./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=1 -compare=0 >> test_devID_$devID\_hA_$hA\_hB_$hB\_W_$W\_transpose_1\.log
		done
	done

<file_sep>#include <stdio.h>
#include <omp.h>

void transCPU(float* m, float *mt, int w, int h)
{
	printf("Start CPU transpose...\n");
	int size = w * h;
	int numThreads = (size > omp_get_num_procs()) ? omp_get_num_procs() : size;
#pragma omp parallel for collapse(2)
	for(int row = 0; row < h; row ++)
	{   
		for(int col = 0; col < w; col ++)
		{   
			mt[col*h + row] = m[row*w + col];
		}   
	}   
}

bool compare(float *a, float *b, int size)
{
	for(int i = 0; i < size; i ++)
	{
		if(a[i] != b[i])
			return false;
	}
	return true;
}

void setZeros(float *a, int size)
{
	int numThreads = (size > omp_get_num_procs()) ? omp_get_num_procs() : size;
	omp_set_num_threads(numThreads);
#pragma omp parallel
	{
		int id = omp_get_thread_num();
		int nthrds = omp_get_num_threads();
		for(int i = id; i < size; i = i + nthrds) 
		{   
			a[i] = 0.0;    
		}
	}	
}

double calDiff(float *a, float *b, int size)
{
	int numThreads = (size > omp_get_num_procs()) ? omp_get_num_procs() : size;
	double diffs[numThreads];
	omp_set_num_threads(numThreads);
	int nthreads;
#pragma omp parallel
	{
		int id = omp_get_thread_num();
		int nthrds = omp_get_num_threads();
		if( id == 0) nthreads = nthrds;	
		diffs[id] = 0.0;
		for(int i = id; i < size; i = i + nthrds) 
		{   
//			double tmp = (double) (a[i] - b[i]); 
//			if(id == 0)
//				printf("[%d from %d]: diff=%lf\n", id, nthrds, tmp);
			diffs[id] += (double) (a[i] - b[i]);    
		}
	}	
	double diff = 0.0;
	for (int i = 0; i < nthreads; i++)
		diff += diffs[i];
	return diff;
}


void printMatrix(float *data, int w, int h)
{
	int maxDim = 8;
	int mw, mh; 
	if(w > maxDim)
	{   
		mw = maxDim;
		printf("Print first %d col...\n", maxDim);
	}else
		mw = w;
	if(h > maxDim)
	{   
		mh = maxDim;
		printf("Print first %d row...\n", maxDim);
	}else
		mh = h;



	for(int i = 0; i < mh; i ++) 
	{   
		for(int j = 0; j < mw; j++)
		{   
			printf("%.1f\t", data[i*w + j]); 
		}   
		printf(";\n");
	}   
}

<file_sep>rm myTranspose.out
nvcc -lcublas -O2 -Xcompiler -fopenmp -o myTranspose.out myTranspose.cu
./myTranspose.out
<file_sep>rm marshlTest
nvcc -Xcompiler -fopenmp -o marshlTest marshalTest.cu
./marshlTest
<file_sep># CUDA_functions

To test our transpose, run ./c\&r.sh

To test transpose from libmarshal, run ./testMarshl.sh

libmarshal reference: 

Code tested: https://bitbucket.org/ijsung/libmarshal/wiki/Home

Paper: http://dl.acm.org/citation.cfm?id=2555266
<file_sep>f = open('forCalAvg.txt')
line = f.readline()
name = []
throughput = []
duration = []
num = []

while line:
	if line.split()[0] in name:
		throughput[name.index(line.split()[0])] += float(line.split()[1])
		duration[name.index(line.split()[0])] += float(line.split()[2])
		num[name.index(line.split()[0])] += 1
	else:
		name.append(line.split()[0]);
		throughput.append(float(line.split()[1]))
		duration.append(float(line.split()[2]))
		num.append(1);
	line = f.readline()
f.close()
for i in range(0, len(name)):
	throughput[i] = throughput[i] / num[i]
	duration[i] = duration[i] / num[i]
	print name[i] + ";" + str(throughput[i]) + ";" + str(duration[i])
<file_sep>devID=2
loopNum=20
scaleNum=7

# Test 0 fix
baseHA=128
baseHB=128
baseW=1024
c=0 #compare, no need to compare
for((scaleA=1; scaleA < $scaleNum; scaleA++))
do
	scalerA=$((1))
	for((cnt=0; cnt < scaleA; cnt ++))
	do
		scalerA=$(($scalerA*2))
	done
	hA=$(($baseHA*$scalerA))
	for((scaleB=1; scaleB < $scaleNum; scaleB++))
	do
		scalerB=$((1))
		for((cnt=0; cnt < scaleB; cnt ++))
		do
			scalerB=$(($scalerB*2))
		done
		hB=$(($baseHB*$scalerB))
		for((scaleC=1; scaleC < $scaleNum; scaleC++))
		do
			scalerC=$((1))
			for((cnt=0; cnt < scaleC; cnt ++))
			do
				scalerC=$(($scalerC*2))
			done
			W=$(($baseW*$scalerC))
			for((i=0; i < $loopNum; i++))
			do
				echo
				echo "Test0 ======= ($i): devID=$devID, hA=$hA, hB=$hB, W=$W======="
				echo "-------> No transpose"
				./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=0 -compare=0
				./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=0 -compare=0 >> test_devID_$devID\_hA_$hA\_hB_$hB\_W_$W\_transpose_0\.log
				echo
				echo "-------> Transpose"
				./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=1 -compare=0
				./matrixMulCUBLAS -device=$devID -hA=$hA -hB=$hB -w=$W -transpose=1 -compare=0 >> test_devID_$devID\_hA_$hA\_hB_$hB\_W_$W\_transpose_1\.log
			done
		done
	done
done


