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.

imatcopy.c 5.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 "DIMATCOPY"
  39. #else
  40. #define ERROR_NAME "SIMATCOPY"
  41. #endif
  42. #define BlasRowMajor 0
  43. #define BlasColMajor 1
  44. #define BlasNoTrans 0
  45. #define BlasTrans 1
  46. #undef malloc
  47. #undef free
  48. /* Enables the New IMATCOPY code with inplace operation if lda == ldb */
  49. #define NEW_IMATCOPY
  50. #ifndef CBLAS
  51. void NAME( char* ORDER, char* TRANS, blasint *rows, blasint *cols, FLOAT *alpha, FLOAT *a, blasint *lda, blasint *ldb)
  52. {
  53. char Order, Trans;
  54. int order=-1,trans=-1;
  55. blasint info = -1;
  56. FLOAT *b;
  57. size_t msize;
  58. Order = *ORDER;
  59. Trans = *TRANS;
  60. TOUPPER(Order);
  61. TOUPPER(Trans);
  62. if ( Order == 'C' ) order = BlasColMajor;
  63. if ( Order == 'R' ) order = BlasRowMajor;
  64. if ( Trans == 'N' ) trans = BlasNoTrans;
  65. if ( Trans == 'R' ) trans = BlasNoTrans;
  66. if ( Trans == 'T' ) trans = BlasTrans;
  67. if ( Trans == 'C' ) trans = BlasTrans;
  68. #else
  69. void CNAME( enum CBLAS_ORDER CORDER, enum CBLAS_TRANSPOSE CTRANS, blasint crows, blasint ccols, FLOAT calpha, FLOAT *a, blasint clda, blasint cldb)
  70. {
  71. int order=-1,trans=-1;
  72. blasint info = -1;
  73. FLOAT *b;
  74. size_t msize;
  75. blasint *lda, *ldb, *rows, *cols;
  76. FLOAT *alpha;
  77. if ( CORDER == CblasColMajor) order = BlasColMajor;
  78. if ( CORDER == CblasRowMajor) order = BlasRowMajor;
  79. if ( CTRANS == CblasNoTrans || CTRANS == CblasConjNoTrans) trans = BlasNoTrans;
  80. if ( CTRANS == CblasTrans || CTRANS == CblasConjTrans ) trans = BlasTrans;
  81. rows = &crows;
  82. cols = &ccols;
  83. alpha = &calpha;
  84. lda = &clda;
  85. ldb = &cldb;
  86. #endif
  87. if ( order == BlasColMajor)
  88. {
  89. if ( trans == BlasNoTrans && *ldb < *rows ) info = 9;
  90. if ( trans == BlasTrans && *ldb < *cols ) info = 9;
  91. }
  92. if ( order == BlasRowMajor)
  93. {
  94. if ( trans == BlasNoTrans && *ldb < *cols ) info = 9;
  95. if ( trans == BlasTrans && *ldb < *rows ) info = 9;
  96. }
  97. if ( order == BlasColMajor && *lda < *rows ) info = 7;
  98. if ( order == BlasRowMajor && *lda < *cols ) info = 7;
  99. if ( *cols <= 0 ) info = 4;
  100. if ( *rows <= 0 ) info = 3;
  101. if ( trans < 0 ) info = 2;
  102. if ( order < 0 ) info = 1;
  103. if (info >= 0) {
  104. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  105. return;
  106. }
  107. #ifdef NEW_IMATCOPY
  108. if ( *lda == *ldb && *rows == *cols) {
  109. if ( order == BlasColMajor )
  110. {
  111. if ( trans == BlasNoTrans )
  112. {
  113. IMATCOPY_K_CN(*rows, *cols, *alpha, a, *lda );
  114. }
  115. else
  116. {
  117. IMATCOPY_K_CT(*rows, *cols, *alpha, a, *lda );
  118. }
  119. }
  120. else
  121. {
  122. if ( trans == BlasNoTrans )
  123. {
  124. IMATCOPY_K_RN(*rows, *cols, *alpha, a, *lda );
  125. }
  126. else
  127. {
  128. IMATCOPY_K_RT(*rows, *cols, *alpha, a, *lda );
  129. }
  130. }
  131. return;
  132. }
  133. #endif
  134. if ( *rows > *cols )
  135. msize = (size_t)(*rows) * (*ldb) * sizeof(FLOAT);
  136. else
  137. msize = (size_t)(*cols) * (*ldb) * sizeof(FLOAT);
  138. b = malloc(msize);
  139. if ( b == NULL )
  140. {
  141. printf("Memory alloc failed\n");
  142. exit(1);
  143. }
  144. if ( order == BlasColMajor )
  145. {
  146. if ( trans == BlasNoTrans )
  147. {
  148. OMATCOPY_K_CN(*rows, *cols, *alpha, a, *lda, b, *ldb );
  149. OMATCOPY_K_CN(*rows, *cols, (FLOAT) 1.0 , b, *ldb, a, *ldb );
  150. }
  151. else
  152. {
  153. OMATCOPY_K_CT(*rows, *cols, *alpha, a, *lda, b, *ldb );
  154. OMATCOPY_K_CN(*cols, *rows, (FLOAT) 1.0, b, *ldb, a, *ldb );
  155. }
  156. }
  157. else
  158. {
  159. if ( trans == BlasNoTrans )
  160. {
  161. OMATCOPY_K_RN(*rows, *cols, *alpha, a, *lda, b, *ldb );
  162. OMATCOPY_K_RN(*rows, *cols, (FLOAT) 1.0, b, *ldb, a, *ldb );
  163. }
  164. else
  165. {
  166. OMATCOPY_K_RT(*rows, *cols, *alpha, a, *lda, b, *ldb );
  167. OMATCOPY_K_RN(*cols, *rows, (FLOAT) 1.0, b, *ldb, a, *ldb );
  168. }
  169. }
  170. free(b);
  171. return;
  172. }