MAGMA  1.2.0
MatrixAlgebraonGPUandMulticoreArchitectures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
set_get.cpp
Go to the documentation of this file.
1 /*
2  * -- MAGMA (version 1.2.0) --
3  * Univ. of Tennessee, Knoxville
4  * Univ. of California, Berkeley
5  * Univ. of Colorado, Denver
6  * April 2012
7  *
8  * @author Mark Gates
9  * @precisions normal z -> s d c
10  */
11 
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <assert.h>
15 
16 #include "magma.h"
17 
18 #ifdef HAVE_CUBLAS
19 
20 // generic, type-independent routines to copy data.
21 // type-safe versions which avoid the user needing sizeof(...) are in copy_[sdcz].cpp
22 
23 // ========================================
24 // copying vectors
25 extern "C"
26 void magma_setvector(
27  magma_int_t n, size_t elemSize,
28  void const* hx_src, magma_int_t incx,
29  void* dy_dst, magma_int_t incy )
30 {
31  cublasStatus_t status;
32  status = cublasSetVector(
33  n, elemSize,
34  hx_src, incx,
35  dy_dst, incy );
36  assert( status == CUBLAS_STATUS_SUCCESS );
37 }
38 
39 // --------------------
40 extern "C"
41 void magma_getvector(
42  magma_int_t n, size_t elemSize,
43  void const* dx_src, magma_int_t incx,
44  void* hy_dst, magma_int_t incy )
45 {
46  cublasStatus_t status;
47  status = cublasGetVector(
48  n, elemSize,
49  dx_src, incx,
50  hy_dst, incy );
51  assert( status == CUBLAS_STATUS_SUCCESS );
52 }
53 
54 // --------------------
55 extern "C"
57  magma_int_t n, size_t elemSize,
58  void const* hx_src, magma_int_t incx,
59  void* dy_dst, magma_int_t incy,
60  cudaStream_t stream )
61 {
62  cublasStatus_t status;
63  status = cublasSetVectorAsync(
64  n, elemSize,
65  hx_src, incx,
66  dy_dst, incy, stream );
67  assert( status == CUBLAS_STATUS_SUCCESS );
68 }
69 
70 // --------------------
71 extern "C"
73  magma_int_t n, size_t elemSize,
74  void const* dx_src, magma_int_t incx,
75  void* hy_dst, magma_int_t incy,
76  cudaStream_t stream )
77 {
78  cublasStatus_t status;
79  status = cublasGetVectorAsync(
80  n, elemSize,
81  dx_src, incx,
82  hy_dst, incy, stream );
83  assert( status == CUBLAS_STATUS_SUCCESS );
84 }
85 
86 
87 // ========================================
88 // copying sub-matrices (contiguous columns)
89 extern "C"
90 void magma_setmatrix(
91  magma_int_t m, magma_int_t n, size_t elemSize,
92  void const* hA_src, magma_int_t lda,
93  void* dB_dst, magma_int_t ldb )
94 {
95  cublasStatus_t status;
96  status = cublasSetMatrix(
97  m, n, elemSize,
98  hA_src, lda,
99  dB_dst, ldb );
100  assert( status == CUBLAS_STATUS_SUCCESS );
101 }
102 
103 // --------------------
104 extern "C"
105 void magma_getmatrix(
106  magma_int_t m, magma_int_t n, size_t elemSize,
107  void const* dA_src, magma_int_t lda,
108  void* hB_dst, magma_int_t ldb )
109 {
110  cublasStatus_t status;
111  status = cublasGetMatrix(
112  m, n, elemSize,
113  dA_src, lda,
114  hB_dst, ldb );
115  assert( status == CUBLAS_STATUS_SUCCESS );
116 }
117 
118 // --------------------
119 extern "C"
120 void magma_setmatrix_async(
121  magma_int_t m, magma_int_t n, size_t elemSize,
122  void const* hA_src, magma_int_t lda,
123  void* dB_dst, magma_int_t ldb,
124  cudaStream_t stream )
125 {
126  cublasStatus_t status;
127  status = cublasSetMatrixAsync(
128  m, n, elemSize,
129  hA_src, lda,
130  dB_dst, ldb, stream );
131  assert( status == CUBLAS_STATUS_SUCCESS );
132 }
133 
134 // --------------------
135 extern "C"
136 void magma_getmatrix_async(
137  magma_int_t m, magma_int_t n, size_t elemSize,
138  void const* dA_src, magma_int_t lda,
139  void* hB_dst, magma_int_t ldb,
140  cudaStream_t stream )
141 {
142  cublasStatus_t status;
143  status = cublasGetMatrixAsync(
144  m, n, elemSize,
145  dA_src, lda,
146  hB_dst, ldb, stream );
147  assert( status == CUBLAS_STATUS_SUCCESS );
148 }
149 
150 // --------------------
151 extern "C"
152 void magma_copymatrix(
153  magma_int_t m, magma_int_t n, size_t elemSize,
154  void const* dA_src, magma_int_t lda,
155  void* dB_dst, magma_int_t ldb )
156 {
157  cudaError_t status;
158  status = cudaMemcpy2D(
159  dB_dst, ldb*elemSize,
160  dA_src, lda*elemSize,
161  m*elemSize, n, cudaMemcpyDeviceToDevice );
162  assert( status == cudaSuccess );
163 }
164 
165 // --------------------
166 extern "C"
167 void magma_copymatrix_async(
168  magma_int_t m, magma_int_t n, size_t elemSize,
169  void const* dA_src, magma_int_t lda,
170  void* dB_dst, magma_int_t ldb,
171  cudaStream_t stream )
172 {
173  cudaError_t status;
174  status = cudaMemcpy2DAsync(
175  dB_dst, ldb*elemSize,
176  dA_src, lda*elemSize,
177  m*elemSize, n, cudaMemcpyDeviceToDevice, stream );
178  assert( status == cudaSuccess );
179 }
180 
181 #endif // HAVE_CUBLAS