Note that there are some explanatory texts on larger screens.

plurals
  1. POcudaMemcpy not copying the host matrix to device (gives segmentation fault)
    primarykey
    data
    text
    <p>Below is the code where i get Segmentation fault when i am trying to print the matrix d_A which is being copied from host matrix h_A.when i am trying to print matrix h_A just before cudamalloc it gets printed but after cudamemcpy trying to print d_A(Device matrix) gives me error.</p> <p>I am using the following:- nvcc -arch=sm_20 Trial.cu -o out to compile </p> <pre><code> #include &lt;stdio.h&gt; #include &lt;sstream&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; #include &lt;math.h&gt; #include &lt;unistd.h&gt; #include &lt;sys/time.h&gt; #include &lt;stdint.h&gt; #include &lt;cuda.h&gt; #include &lt;time.h&gt; inline void gpuAssert(cudaError_t code, char *file, int line, bool abort=true) { if (code != cudaSuccess) { fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line); if (abort) exit(code); } } void LUdecomposition(float *h_A,float *A_,int dim,unsigned int size_A,int row_A) { float *d_A;int k; gpuErrchk(cudaMalloc(&amp;d_A, size_A*sizeof(float))); gpuErrchk(cudaMemcpy(d_A, h_A, size_A*sizeof(float), cudaMemcpyHostToDevice)); printf("\n D_A"); gpuErrchk(cudaMemcpy(A_,d_A,size_A*sizeof(float), cudaMemcpyDeviceToHost)); for(int i=0; i&lt;size_A; i++) { if (i % row_A == 0) printf("\n"); printf("%f ", A_[i]); } printf("\n D_A"); } void input_matrix_generation_A(float *Matrix, unsigned int row, unsigned int column, unsigned int size) { for (int i=0; i&lt;size; i++) { Matrix[i] = rand()%5+1; if (i % column == 0) printf("\n"); } } int main(int argc, char *argv[]) { int m=4;int dim=2; int size_A=m*m; float *A, *A_; A = (float*)malloc(sizeof(float)*size_A); input_matrix_generation_A(A,m,m,size_A); A_ = (float*)malloc(sizeof(float)*size_A); LUdecomposition(A,A_,dim,size_A,m); for(int i=0; i&lt;size_A; i++) { if (i % row_A == 0) printf("\n"); printf("%f ", A_[i]); } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload