I'm using bash to retrieve kernels from a cuda program using the following code:
kername="kernelnames"
loop="loop"
filecp="filecp"
funct="funct"
truncate -s 0 $kername
truncate -s 0 $loop
truncate -s 0 $funct
counter=1
funct_display(){
count=0
flag=1
while read line ; do
echo "$line"
if [[ "$line" == "{" ]] ; then echo "$line"; count=$(( count+1 )) ; echo "$counter $count incre" ;fi
if [[ "$line" == "}" ]] ; then count=$(( count-1 )) ; echo "$counter $count decre" ;fi
if [[ $count > 0 ]] ; then echo "$line" >> $funct ;fi
if [[ $count == 0 ]] ; then flag=0 ; fi
if [[ $flag == 0 ]] ; then break ; fi
#if [[ $count == 0 ]] ; then counter=$(( counter+1 )); fi
counter=$(( counter+1 ))
done < $filecp
echo "}" >> $funct
echo "" >>$funct
}
file_copy(){
truncate -s 0 $filecp
while read line; do
echo "$line" >> $filecp
done < $filename
}
read -p "Enter the name of the file to be scanned: " filename
var=$( grep "__global__" < $filename | wc -l )
echo "kernels" >> $kername
for((i=1;i<=$var;i++))
do
temp1=$( grep -m$i "__global__" < $filename | tail -n1 )
a=$( grep -n -m$i "__global__" < $filename | cut -d : -f 1 | tail -n1 )
j=$(( i+1 ))
temp2=$( grep -m$j "__global__" < $filename | tail -n1 )
b=$( grep -n -m$j "__global__" < $filename | cut -d : -f 1 | tail -n1 )
echo "$i $temp1 $a $b" >> $kername
temp5=$( sed -n " $a , $b p" $filename )
echo "$temp5" >> $loop
#echo "$a"
while read line ; do
if [[ "$line" == "$temp1" ]] ; then
echo "$line " >> $funct
echo "$line"
file_copy
for((k=$a;k>0;k--))
do
echo "$k"
sed -i "${k}d" $filecp
done
funct_display
fi
done < $filename
#echo "$temp1"
done
The above shell script is working for a program with following kernels:
__global__ void addKernel(int *c, const int *a, const int *b)
{
int i = threadIdx.x;
c[i] = a[i] + b[i];
}
__global__ void subKernel(int *c, const int *a, const int *b)
{
int i = threadIdx.x;
c[i] = a[i] - b[i];
}
But it won't work for a program with the following kernel:
__global__ void Vec_Mat_mul(float *gV, float*gM, float *gR, int Vecsize, int Matcols)
{ int i, j;
float sum=0.0;
i=(blockIdx.x*blockDim.x)+threadIdx.x; //For each block access
if(i<Matcols)
{
for(j=0;j<Vecsize;j++)
sum=sum+(gV[j]*gM[j+(i*Vecsize)]);
__syncthreads(); //Synchronization Barrier
gR[i]=sum;
}
}
I figured that it is not entering the if statement : if [[ "$line" == "{" ]] for some reason but I can't understand why. Thank you in advance!
Aucun commentaire:
Enregistrer un commentaire