मैं इस प्रकार आव्यूह गुणन के लिए एक चर घोषित करने के लिए कोशिश कर रहा हूँ:Cuda साझा मेमोरी सरणी चर
__shared__ float As[BLOCK_SIZE][BLOCK_SIZE];
मैं यह इतना उपयोगकर्ता इनपुट मैट्रिक्स के आकार की गणना करने के लिए कर सकता है बनाने की कोशिश कर रहा हूँ कि होगा हालांकि, मतलब BLOCK_SIZE बदल रहा है। मैंने इसे बदल दिया लेकिन मुझे एक कंपाइलर त्रुटि मिल रही है: "त्रुटि: निरंतर मान ज्ञात नहीं है"। मैंने इसे देखा है और यह thread के समान है। इसलिए मैं करने की कोशिश की:
__shared__ int buf [];
लेकिन तब मैं मिलता है: "त्रुटि: अधूरा प्रकार अनुमत नहीं है"
धन्यवाद, कोड के साथ दान अद्यतन (काफी this guide पीछा किया और CUDA गाइड के साथ बाहर घूर) : ब्लॉक आकार को मैट्रिक्स के आकार के उपयोगकर्ता से पूछकर पारित किया जाता है। वे एक्स और वाई दर्ज करते हैं। ब्लॉक आकार केवल एक्स है और अभी इसे एक्स और वाई के समान आकार को स्वीकार करना है।
__global__ void matrixMul(float* C, float* A, float* B, int wA, int wB,size_t block_size)
{
// Block index
int bx = blockIdx.x;
int by = blockIdx.y;
// Thread index
int tx = threadIdx.x;
int ty = threadIdx.y;
// Index of the first sub-matrix of A processed
// by the block
int aBegin = wA * block_size * by;
// Index of the last sub-matrix of A processed
// by the block
int aEnd = aBegin + wA - 1;
// Step size used to iterate through the
// sub-matrices of A
int aStep = block_size;
// Index of the first sub-matrix of B processed
// by the block
int bBegin = block_size * bx;
// Step size used to iterate through the
// sub-matrices of B
int bStep = block_size * wB;
float Csub=0;
// Loop over all the sub-matrices of A and B
// required to compute the block sub-matrix
for (int a = aBegin, b = bBegin; a <= aEnd; a += aStep, b += bStep)
{
// Declaration of the shared memory array As
// used to store the sub-matrix of A
extern __shared__ float As[];
// Declaration of the shared memory array Bs
// used to store the sub-matrix of B
extern __shared__ float Bs[];
extern __shared__ float smem[];
// Load the matrices from global memory
// to shared memory; each thread loads
// one element of each matrix
smem[ty*block_size+tx] = A[a + wA * ty + tx];
//cuPrintf("\n\nWhat are the memory locations?\n");
//cuPrintf("The shared memory(A) is: %.2f\n",smem[ty*block_size+tx]);
smem[block_size*block_size+ty*block_size+tx] = B[b + wB * ty + tx];
//cuPrintf("The shared memory(B) is: %.2f\n",smem[block_size*block_size+ty*block_size+tx]);
// Synchronize to make sure the matrices
// are loaded
__syncthreads();
// Multiply the two matrices together;
// each thread computes one element
// of the block sub-matrix
for (int k = 0; k < block_size; ++k)
{
Csub += smem[ty*block_size+k] * smem[block_size*block_size+k*block_size+tx] ;
//cuPrintf("Csub is currently: %.2f\n",Csub);
}
//cuPrintf("\n\n\n");
// Synchronize to make sure that the preceding
// computation is done before loading two new
// sub-matrices of A and B in the next iteration
//cuPrintf("the results are csub: %.2f\n",Csub);
__syncthreads();
}
// Write the block sub-matrix to device memory;
// each thread writes one element
int c = wB * block_size * by + block_size * bx;
C[c + wB * ty + tx] = Csub;
}
धागा का उपयोग आप एक गलती निहित से जुड़ा हुआ। – talonmies
आह मैं देखता हूं कि आपने इसे संपादित किया, धन्यवाद। – Dan