Question

4A. Write a CUDA host program that reads a character type matrix A and integer type matrix B of size mxn. It produces an outp

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

__global__void cuda_print(int m, int n, int **x, char **y)
{
   int k=0;
   char *STR;
  
  
for(int i=0;i<m;i++)
{
   for(int j =0;j<n;j++)
   {
       while(yx[i][j]]--)
       {
           STR[k++] = y[i][j];
       }
   }
}
  
printf("%s",STR);
}

int main(void)
{
int m,n;
printf("Enter the values of m and n : ");
scanf("%d %d",&m,&n);
  
char** str = new char*[10000];
for (int i=0;i<10000;i++)
   str[i] = new char[20];
  
int** x = new int*[10000];
for (int i=0;i<10000;i++)
   x[i] = new int[20];

int **d_x;
char **d_str;
char **STR;
  
cudaMalloc(&d_x, m*n*sizeof(int));
cudaMalloc(&d_str, m*n*sizeof(char));
cudaMalloc(&STR, 10000*sizeof(char));

for (int i = 0; i < m; i++) {
   for(int j = 0; j < n; j++ )
       scanf("%d",x[i][j]]);
       scanf("%c",str[i][j]]);
   }
}

cudaMemcpy(d_x, x, m*n*sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(d_str, str, m*n*sizeof(char), cudaMemcpyHostToDevice);

// Kernel for device
cuda_print<<<1,1>>>(m, n, d_x, d_str);

cudaFree(d_x);
cudaFree(d_str);
free(x);
free(str);
}

Add a comment
Know the answer?
Add Answer to:
4A. Write a CUDA host program that reads a character type matrix A and integer type matrix B of size mxn. It produces an output string STR such that, every character of A is repeated n times (where n...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT