You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

zimatcopy.c 7.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /***************************************************************************
  2. Copyright (c) 2014, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *****************************************************************************/
  27. /***********************************************************
  28. * 2014-06-10 Saar
  29. * 2015-09-07 grisuthedragon
  30. ***********************************************************/
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include "common.h"
  34. #ifdef FUNCTION_PROFILE
  35. #include "functable.h"
  36. #endif
  37. #if defined(DOUBLE)
  38. #define ERROR_NAME "ZIMATCOPY"
  39. #else
  40. #define ERROR_NAME "CIMATCOPY"
  41. #endif
  42. #define BlasRowMajor 0
  43. #define BlasColMajor 1
  44. #define BlasNoTrans 0
  45. #define BlasTrans 1
  46. #define BlasTransConj 2
  47. #define BlasConj 3
  48. #define NEW_IMATCOPY
  49. #ifndef CBLAS
  50. void NAME( char* ORDER, char* TRANS, blasint *rows, blasint *cols, FLOAT *alpha, FLOAT *a, blasint *lda, blasint *ldb)
  51. {
  52. char Order, Trans;
  53. int order=-1,trans=-1;
  54. blasint info = -1;
  55. FLOAT *b;
  56. size_t msize;
  57. Order = *ORDER;
  58. Trans = *TRANS;
  59. TOUPPER(Order);
  60. TOUPPER(Trans);
  61. if ( Order == 'C' ) order = BlasColMajor;
  62. if ( Order == 'R' ) order = BlasRowMajor;
  63. if ( Trans == 'N' ) trans = BlasNoTrans;
  64. if ( Trans == 'T' ) trans = BlasTrans;
  65. if ( Trans == 'C' ) trans = BlasTransConj;
  66. if ( Trans == 'R' ) trans = BlasConj;
  67. #else
  68. void CNAME( enum CBLAS_ORDER CORDER, enum CBLAS_TRANSPOSE CTRANS, blasint crows, blasint ccols, FLOAT *alpha, FLOAT *a, blasint clda, blasint cldb)
  69. {
  70. blasint *rows, *cols, *lda, *ldb;
  71. int order=-1,trans=-1;
  72. blasint info = -1;
  73. FLOAT *b;
  74. size_t msize;
  75. if ( CORDER == CblasColMajor ) order = BlasColMajor;
  76. if ( CORDER == CblasRowMajor ) order = BlasRowMajor;
  77. if ( CTRANS == CblasNoTrans) trans = BlasNoTrans;
  78. if ( CTRANS == CblasConjNoTrans ) trans = BlasConj;
  79. if ( CTRANS == CblasTrans) trans = BlasTrans;
  80. if ( CTRANS == CblasConjTrans) trans = BlasTransConj;
  81. rows = &crows;
  82. cols = &ccols;
  83. lda = &clda;
  84. ldb = &cldb;
  85. #endif
  86. if ( order == BlasColMajor)
  87. {
  88. if ( trans == BlasNoTrans && *ldb < MAX(1,*rows) ) info = 9;
  89. if ( trans == BlasConj && *ldb < MAX(1,*rows) ) info = 9;
  90. if ( trans == BlasTrans && *ldb < MAX(1,*cols) ) info = 9;
  91. if ( trans == BlasTransConj && *ldb < MAX(1,*cols) ) info = 9;
  92. }
  93. if ( order == BlasRowMajor)
  94. {
  95. if ( trans == BlasNoTrans && *ldb < MAX(1,*cols) ) info = 9;
  96. if ( trans == BlasConj && *ldb < MAX(1,*cols) ) info = 9;
  97. if ( trans == BlasTrans && *ldb < MAX(1,*rows) ) info = 9;
  98. if ( trans == BlasTransConj && *ldb < MAX(1,*rows) ) info = 9;
  99. }
  100. if ( order == BlasColMajor && *lda < MAX(1,*rows) ) info = 7;
  101. if ( order == BlasRowMajor && *lda < MAX(1,*cols) ) info = 7;
  102. if ( *cols < 0 ) info = 4;
  103. if ( *rows < 0 ) info = 3;
  104. if ( trans < 0 ) info = 2;
  105. if ( order < 0 ) info = 1;
  106. if (info >= 0) {
  107. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  108. return;
  109. }
  110. if ((*rows == 0) || (*cols == 0)) return;
  111. #ifdef NEW_IMATCOPY
  112. if (*lda == *ldb ) {
  113. if ( order == BlasColMajor )
  114. {
  115. if ( trans == BlasNoTrans )
  116. {
  117. IMATCOPY_K_CN(*rows, *cols, alpha[0], alpha[1], a, *lda );
  118. return;
  119. }
  120. if ( trans == BlasConj )
  121. {
  122. IMATCOPY_K_CNC(*rows, *cols, alpha[0], alpha[1], a, *lda );
  123. return;
  124. }
  125. if ( trans == BlasTrans && *rows == *cols )
  126. {
  127. IMATCOPY_K_CT(*rows, *cols, alpha[0], alpha[1], a, *lda );
  128. return;
  129. }
  130. if ( trans == BlasTransConj && *rows == *cols )
  131. {
  132. IMATCOPY_K_CTC(*rows, *cols, alpha[0], alpha[1], a, *lda );
  133. return;
  134. }
  135. }
  136. else
  137. {
  138. if ( trans == BlasNoTrans )
  139. {
  140. IMATCOPY_K_RN(*rows, *cols, alpha[0], alpha[1], a, *lda );
  141. return;
  142. }
  143. if ( trans == BlasConj )
  144. {
  145. IMATCOPY_K_RNC(*rows, *cols, alpha[0], alpha[1], a, *lda );
  146. return;
  147. }
  148. if ( trans == BlasTrans && *rows == *cols )
  149. {
  150. IMATCOPY_K_RT(*rows, *cols, alpha[0], alpha[1], a, *lda );
  151. return;
  152. }
  153. if ( trans == BlasTransConj && *rows == *cols )
  154. {
  155. IMATCOPY_K_RTC(*rows, *cols, alpha[0], alpha[1], a, *lda );
  156. return;
  157. }
  158. }
  159. }
  160. #endif
  161. msize = (size_t)(*rows) * (*cols) * sizeof(FLOAT) * 2;
  162. b = malloc(msize);
  163. if ( b == NULL )
  164. {
  165. printf("Memory alloc failed in zimatcopy\n");
  166. exit(1);
  167. }
  168. if ( order == BlasColMajor )
  169. {
  170. if ( trans == BlasNoTrans )
  171. {
  172. OMATCOPY_K_CN(*rows, *cols, alpha[0], alpha[1], a, *lda, b, *rows );
  173. OMATCOPY_K_CN(*rows, *cols, (FLOAT) 1.0, (FLOAT) 0.0 , b, *rows, a, *ldb );
  174. }
  175. else if ( trans == BlasConj )
  176. {
  177. OMATCOPY_K_CNC(*rows, *cols, alpha[0], alpha[1], a, *lda, b, *rows );
  178. OMATCOPY_K_CN(*rows, *cols, (FLOAT) 1.0, (FLOAT) 0.0 , b, *rows, a, *ldb );
  179. }
  180. else if ( trans == BlasTrans )
  181. {
  182. OMATCOPY_K_CT(*rows, *cols, alpha[0], alpha[1], a, *lda, b, *cols );
  183. OMATCOPY_K_CN(*cols, *rows, (FLOAT) 1.0, (FLOAT) 0.0 , b, *cols, a, *ldb );
  184. }
  185. else if ( trans == BlasTransConj )
  186. {
  187. OMATCOPY_K_CTC(*rows, *cols, alpha[0], alpha[1], a, *lda, b, *cols );
  188. OMATCOPY_K_CN(*cols, *rows, (FLOAT) 1.0, (FLOAT) 0.0 , b, *cols, a, *ldb );
  189. }
  190. }
  191. else
  192. {
  193. if ( trans == BlasNoTrans )
  194. {
  195. OMATCOPY_K_RN(*rows, *cols, alpha[0], alpha[1], a, *lda, b, *cols );
  196. OMATCOPY_K_RN(*rows, *cols, (FLOAT) 1.0, (FLOAT) 0.0 , b, *cols, a, *ldb );
  197. }
  198. else if ( trans == BlasConj )
  199. {
  200. OMATCOPY_K_RNC(*rows, *cols, alpha[0], alpha[1], a, *lda, b, *cols );
  201. OMATCOPY_K_RN(*rows, *cols, (FLOAT) 1.0, (FLOAT) 0.0 , b, *cols, a, *ldb );
  202. }
  203. else if ( trans == BlasTrans )
  204. {
  205. OMATCOPY_K_RT(*rows, *cols, alpha[0], alpha[1], a, *lda, b, *rows );
  206. OMATCOPY_K_RN(*cols, *rows, (FLOAT) 1.0, (FLOAT) 0.0 , b, *rows, a, *ldb );
  207. }
  208. else if ( trans == BlasTransConj )
  209. {
  210. OMATCOPY_K_RTC(*rows, *cols, alpha[0], alpha[1], a, *lda, b, *rows );
  211. OMATCOPY_K_RN(*cols, *rows, (FLOAT) 1.0, (FLOAT) 0.0 , b, *rows, a, *ldb );
  212. }
  213. }
  214. free(b);
  215. return;
  216. }