Hi Everyone,I have a problem with kernel execution in the code below: from numpy import *from matplotlib import *from pycuda import *from scipy import *import pycuda.driver as cudaimport pycuda.autoinitfrom pycuda.compiler import SourceModule ##from Bio import SeqIO##handle=open("homosapiens.fasta","rU")##for record in SeqIO.parse(handle,"fasta"):## print record.id##handle.close()####dna=record.seq##seq=dna.transcribe() seq='AACUUCUUCAA'
def score_bpair(seq,i,j,soglia=2): score={('A','U'):1,('U','A'):1,('C','G'):1,('G','C'):1} a=seq[i] b=seq[j] if(abs(i-j)<soglia or((a,b) not in score.keys())): return 0 else: return score[(a,b)] L=len(seq);smat=zeros((L,L)); #allocazione memoriasmat_gpu = cuda.mem_alloc(smat.nbytes) #allochiamo uno spazio di dimensioni pari alla dimensione dell'arraycuda.memcpy_htod(smat_gpu, smat) ### kernel 1mod = SourceModule("""__global__ void alg_nussinov( int *smat_gpu) { int i = threadIdx.x; int j = threadIdx.y; int L; int s; int *retval; for(i=0;i<L-s;i++) { j=i+s; int maxfork=0; for(int k=i;k<j-1;k++) { if ( maxfork > (*(smat_gpu+i*L+k) + *(smat_gpu + (k+1)*L+j) )) *retval = maxfork; else *retval = ( *(smat_gpu+i*L+k) + *(smat_gpu+(k+1)*L+j)); } if ( *(smat_gpu+(i+1)*L+(j-1)) > *retval) *(smat_gpu+i*L+j) = *(smat_gpu+(i+1)*L+(j-1)); else *(smat_gpu+i*L+j) = *(retval+3); *(smat_gpu+j*L+i) = *(smat_gpu+i*L+j); }} """) def nussinov(seq):## L=len(seq);## smat=zeros((L,L)); for s in xrange(1,L): nuss_gpu = mod.get_function("alg_nussinov") nuss_gpu(smat_gpu,block =(L,L,1)) smat_doubled = numpy.empty_like(smat) cuda.memcpy_dtoh(smat_doubled, smat_gpu) return(smat_doubled) ####def traceback(seq,smat=nussinov(seq)):## L=len(seq)## paired=['.']*L## q=[]## q.append((0,len(seq)-1))## while (q!=[]):## (i,j)=q.pop()## if(i<j):## if(smat[i+1][j] == smat[i][j]):## q.append((i+1,j))## elif(smat[i][j-1] == smat[i][j]):## q.append((i,j-1))## elif(smat[i+1][j-1]+score_bpair(seq,i,j) == smat[i][j]):## paired[i]='('## paired[j]=')'## q.append((i,j-1))## else:## for k in xrange(i+1,j-1):## if (smat[i][k] + smat[k+1][j] == smat[i][j]):## q.append((k+1,j))## q.append((i,k))## return(paired)###### When I run the code, I try to print something writing print nussinov(seq) but operation doesn't work because kernel execution gives to me a matrix like this: [[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 1. 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. 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. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] Matrix resulting printing nussinov(seq) for a sequence of 11 elements. Kernel doesn't work [ 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. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]] [[ 0. 0. 0. 1. 2. 1. 2. 2. 2. 3. 4.] [ 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 3.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 2.] [ 1. 1. 0. 0. 0. 0. 0. 0. 0. 1. 2.] [ 2. 1. 0. 0. 0. 0. 0. 0. 0. 1. 2.] [ 1. 1. 0. 0. 0. 0. 0. 0. 0. 1. 2.] [ 2. 1. 0. 0. 0. 0. 0. 0. 0. 1. 2.] Matrix resulting printing nussinov(seq) for a sequence of 11 elements. Kernel works [ 2. 1. 0. 0. 0. 0. 0. 0. 0. 1. 1.] [ 2. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 3. 2. 1. 1. 1. 1. 1. 1. 0. 0. 0.] [ 4. 3. 2. 2. 2. 2. 2. 1. 0. 0. 0.]] Could someone help me?? I don't understand how to solve my problem.Thanks a lot
_______________________________________________ PyCUDA mailing list PyCUDA@tiker.net http://lists.tiker.net/listinfo/pycuda