blob: 7af61acc174639e7cd6a0d1494083c95cbab2f7b [file] [log] [blame]
Tim Murray25207df2015-01-12 16:47:56 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.renderscript;
18
19import android.annotation.IntDef;
20import java.lang.annotation.Retention;
21import java.lang.annotation.RetentionPolicy;
22
23/**
24 *
25 * BLAS
26 *
27 * @hide
28 **/
29public final class ScriptIntrinsicBLAS extends ScriptIntrinsic {
30 private Allocation mLUT;
31
32 private ScriptIntrinsicBLAS(long id, RenderScript rs) {
33 super(id, rs);
34 }
35
36 private static final int RsBlas_sdsdot = 1;
37 private static final int RsBlas_dsdot = 2;
38 private static final int RsBlas_sdot = 3;
39 private static final int RsBlas_ddot = 4;
40 private static final int RsBlas_cdotu_sub = 5;
41 private static final int RsBlas_cdotc_sub = 6;
42 private static final int RsBlas_zdotu_sub = 7;
43 private static final int RsBlas_zdotc_sub = 8;
44 private static final int RsBlas_snrm2 = 9;
45 private static final int RsBlas_sasum = 10;
46 private static final int RsBlas_dnrm2 = 11;
47 private static final int RsBlas_dasum = 12;
48 private static final int RsBlas_scnrm2 = 13;
49 private static final int RsBlas_scasum = 14;
50 private static final int RsBlas_dznrm2 = 15;
51 private static final int RsBlas_dzasum = 16;
52 private static final int RsBlas_isamax = 17;
53 private static final int RsBlas_idamax = 18;
54 private static final int RsBlas_icamax = 19;
55 private static final int RsBlas_izamax = 20;
56 private static final int RsBlas_sswap = 21;
57 private static final int RsBlas_scopy = 22;
58 private static final int RsBlas_saxpy = 23;
59 private static final int RsBlas_dswap = 24;
60 private static final int RsBlas_dcopy = 25;
61 private static final int RsBlas_daxpy = 26;
62 private static final int RsBlas_cswap = 27;
63 private static final int RsBlas_ccopy = 28;
64 private static final int RsBlas_caxpy = 29;
65 private static final int RsBlas_zswap = 30;
66 private static final int RsBlas_zcopy = 31;
67 private static final int RsBlas_zaxpy = 32;
68 private static final int RsBlas_srotg = 33;
69 private static final int RsBlas_srotmg = 34;
70 private static final int RsBlas_srot = 35;
71 private static final int RsBlas_srotm = 36;
72 private static final int RsBlas_drotg = 37;
73 private static final int RsBlas_drotmg = 38;
74 private static final int RsBlas_drot = 39;
75 private static final int RsBlas_drotm = 40;
76 private static final int RsBlas_sscal = 41;
77 private static final int RsBlas_dscal = 42;
78 private static final int RsBlas_cscal = 43;
79 private static final int RsBlas_zscal = 44;
80 private static final int RsBlas_csscal = 45;
81 private static final int RsBlas_zdscal = 46;
82 private static final int RsBlas_sgemv = 47;
83 private static final int RsBlas_sgbmv = 48;
84 private static final int RsBlas_strmv = 49;
85 private static final int RsBlas_stbmv = 50;
86 private static final int RsBlas_stpmv = 51;
87 private static final int RsBlas_strsv = 52;
88 private static final int RsBlas_stbsv = 53;
89 private static final int RsBlas_stpsv = 54;
90 private static final int RsBlas_dgemv = 55;
91 private static final int RsBlas_dgbmv = 56;
92 private static final int RsBlas_dtrmv = 57;
93 private static final int RsBlas_dtbmv = 58;
94 private static final int RsBlas_dtpmv = 59;
95 private static final int RsBlas_dtrsv = 60;
96 private static final int RsBlas_dtbsv = 61;
97 private static final int RsBlas_dtpsv = 62;
98 private static final int RsBlas_cgemv = 63;
99 private static final int RsBlas_cgbmv = 64;
100 private static final int RsBlas_ctrmv = 65;
101 private static final int RsBlas_ctbmv = 66;
102 private static final int RsBlas_ctpmv = 67;
103 private static final int RsBlas_ctrsv = 68;
104 private static final int RsBlas_ctbsv = 69;
105 private static final int RsBlas_ctpsv = 70;
106 private static final int RsBlas_zgemv = 71;
107 private static final int RsBlas_zgbmv = 72;
108 private static final int RsBlas_ztrmv = 73;
109 private static final int RsBlas_ztbmv = 74;
110 private static final int RsBlas_ztpmv = 75;
111 private static final int RsBlas_ztrsv = 76;
112 private static final int RsBlas_ztbsv = 77;
113 private static final int RsBlas_ztpsv = 78;
114 private static final int RsBlas_ssymv = 79;
115 private static final int RsBlas_ssbmv = 80;
116 private static final int RsBlas_sspmv = 81;
117 private static final int RsBlas_sger = 82;
118 private static final int RsBlas_ssyr = 83;
119 private static final int RsBlas_sspr = 84;
120 private static final int RsBlas_ssyr2 = 85;
121 private static final int RsBlas_sspr2 = 86;
122 private static final int RsBlas_dsymv = 87;
123 private static final int RsBlas_dsbmv = 88;
124 private static final int RsBlas_dspmv = 89;
125 private static final int RsBlas_dger = 90;
126 private static final int RsBlas_dsyr = 91;
127 private static final int RsBlas_dspr = 92;
128 private static final int RsBlas_dsyr2 = 93;
129 private static final int RsBlas_dspr2 = 94;
130 private static final int RsBlas_chemv = 95;
131 private static final int RsBlas_chbmv = 96;
132 private static final int RsBlas_chpmv = 97;
133 private static final int RsBlas_cgeru = 98;
134 private static final int RsBlas_cgerc = 99;
135 private static final int RsBlas_cher = 100;
136 private static final int RsBlas_chpr = 101;
137 private static final int RsBlas_cher2 = 102;
138 private static final int RsBlas_chpr2 = 103;
139 private static final int RsBlas_zhemv = 104;
140 private static final int RsBlas_zhbmv = 105;
141 private static final int RsBlas_zhpmv = 106;
142 private static final int RsBlas_zgeru = 107;
143 private static final int RsBlas_zgerc = 108;
144 private static final int RsBlas_zher = 109;
145 private static final int RsBlas_zhpr = 110;
146 private static final int RsBlas_zher2 = 111;
147 private static final int RsBlas_zhpr2 = 112;
148 private static final int RsBlas_sgemm = 113;
149 private static final int RsBlas_ssymm = 114;
150 private static final int RsBlas_ssyrk = 115;
151 private static final int RsBlas_ssyr2k = 116;
152 private static final int RsBlas_strmm = 117;
153 private static final int RsBlas_strsm = 118;
154 private static final int RsBlas_dgemm = 119;
155 private static final int RsBlas_dsymm = 120;
156 private static final int RsBlas_dsyrk = 121;
157 private static final int RsBlas_dsyr2k = 122;
158 private static final int RsBlas_dtrmm = 123;
159 private static final int RsBlas_dtrsm = 124;
160 private static final int RsBlas_cgemm = 125;
161 private static final int RsBlas_csymm = 126;
162 private static final int RsBlas_csyrk = 127;
163 private static final int RsBlas_csyr2k = 128;
164 private static final int RsBlas_ctrmm = 129;
165 private static final int RsBlas_ctrsm = 130;
166 private static final int RsBlas_zgemm = 131;
167 private static final int RsBlas_zsymm = 132;
168 private static final int RsBlas_zsyrk = 133;
169 private static final int RsBlas_zsyr2k = 134;
170 private static final int RsBlas_ztrmm = 135;
171 private static final int RsBlas_ztrsm = 136;
172 private static final int RsBlas_chemm = 137;
173 private static final int RsBlas_cherk = 138;
174 private static final int RsBlas_cher2k = 139;
175 private static final int RsBlas_zhemm = 140;
176 private static final int RsBlas_zherk = 141;
177 private static final int RsBlas_zher2k = 142;
178
Tim Murray9cb16a22015-04-01 11:07:16 -0700179 // BLAS extensions start here
180 private static final int RsBlas_bnnm = 1000;
181
Tim Murray25207df2015-01-12 16:47:56 -0800182 /**
183 */
184 public static ScriptIntrinsicBLAS create(RenderScript rs) {
185 long id = rs.nScriptIntrinsicCreate(13, Element.U32(rs).getID(rs));
186 return new ScriptIntrinsicBLAS(id, rs);
187 }
188
189 @IntDef({NO_TRANSPOSE, TRANSPOSE, CONJ_TRANSPOSE})
190 @Retention(RetentionPolicy.SOURCE)
191 public @interface Transpose {}
192
193 @IntDef({UPPER, LOWER})
194 @Retention(RetentionPolicy.SOURCE)
195 public @interface Uplo {}
196
197 @IntDef({NON_UNIT, UNIT})
198 @Retention(RetentionPolicy.SOURCE)
199 public @interface Diag {}
200
201 @IntDef({LEFT, RIGHT})
202 @Retention(RetentionPolicy.SOURCE)
203 public @interface Side {}
204
205 public static final int NO_TRANSPOSE = 111;
206 public static final int TRANSPOSE = 112;
207 public static final int CONJ_TRANSPOSE = 113;
208
209 public static final int UPPER = 121;
210 public static final int LOWER = 122;
211
212 public static final int NON_UNIT = 131;
213 public static final int UNIT = 132;
214
215 public static final int LEFT = 141;
216 public static final int RIGHT = 142;
217
218 static void validateSide(@Side int Side) {
219 if (Side != LEFT && Side != RIGHT) {
220 throw new RSRuntimeException("Invalid side passed to BLAS");
221 }
222 }
223
224 static void validateTranspose(@Transpose int Trans) {
225 if (Trans != NO_TRANSPOSE && Trans != TRANSPOSE &&
226 Trans != CONJ_TRANSPOSE) {
227 throw new RSRuntimeException("Invalid transpose passed to BLAS");
228 }
229 }
230
231 static void validateConjTranspose(@Transpose int Trans) {
232 if (Trans != NO_TRANSPOSE &&
233 Trans != CONJ_TRANSPOSE) {
234 throw new RSRuntimeException("Invalid transpose passed to BLAS");
235 }
236 }
237
238 static void validateDiag(@Diag int Diag) {
239 if (Diag != NON_UNIT && Diag != UNIT) {
240 throw new RSRuntimeException("Invalid diag passed to BLAS");
241 }
242 }
243
244 static void validateUplo(@Uplo int Uplo) {
245 if (Uplo != LEFT && Uplo != RIGHT) {
246 throw new RSRuntimeException("Invalid uplo passed to BLAS");
247 }
248 }
249
250
251 /**
252 * Level 2 BLAS
253 */
254
255 static void validateGEMV(Element e, int TransA, Allocation A, Allocation X, int incX, Allocation Y, int incY) {
256 validateTranspose(TransA);
257 int M = A.getType().getY();
258 int N = A.getType().getX();
259 if (!A.getType().getElement().isCompatible(e) ||
260 !X.getType().getElement().isCompatible(e) ||
261 !Y.getType().getElement().isCompatible(e)) {
262 throw new RSRuntimeException("Called BLAS with wrong Element type");
263 }
264 if (X.getType().getY() > 1 || Y.getType().getY() > 1) {
265 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
266 }
267
268 if (incX <= 0 || incY <= 0) {
269 throw new RSRuntimeException("Vector increments must be greater than 0");
270 }
271 int expectedXDim = -1, expectedYDim = -1;
272 if (TransA == NO_TRANSPOSE) {
273 expectedXDim = 1 + (N - 1) * incX;
274 expectedYDim = 1 + (M - 1) * incY;
275 } else {
276 expectedXDim = 1 + (M - 1) * incX;
277 expectedYDim = 1 + (N - 1) * incY;
278 }
279 if (X.getType().getX() != expectedXDim ||
Miao Wang2b6fad92015-04-23 15:06:09 -0700280 Y.getType().getX() != expectedYDim) {
Tim Murray25207df2015-01-12 16:47:56 -0800281 throw new RSRuntimeException("Incorrect vector dimensions for GEMV");
282 }
283 }
284 void SGEMV(@Transpose int TransA, float alpha, Allocation A, Allocation X, int incX, float beta, Allocation Y, int incY) {
285 validateGEMV(Element.F32(mRS), TransA, A, X, incX, Y, incY);
286 int M = A.getType().getY();
287 int N = A.getType().getX();
288 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_sgemv, TransA, 0, 0, 0, 0, M, N, 0, alpha, A.getID(mRS), X.getID(mRS), beta, Y.getID(mRS), incX, incY, 0, 0);
289 }
290 void DGEMV(@Transpose int TransA, double alpha, Allocation A, Allocation X, int incX, double beta, Allocation Y, int incY) {
291 validateGEMV(Element.F64(mRS), TransA, A, X, incX, Y, incY);
292 int M = A.getType().getY();
293 int N = A.getType().getX();
294 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dgemv, TransA, 0, 0, 0, 0, M, N, 0, alpha, A.getID(mRS), X.getID(mRS), beta, Y.getID(mRS), incX, incY, 0, 0);
295 }
296 void CGEMV(@Transpose int TransA, Float2 alpha, Allocation A, Allocation X, int incX, Float2 beta, Allocation Y, int incY) {
297 validateGEMV(Element.F32_2(mRS), TransA, A, X, incX, Y, incY);
298 int M = A.getType().getY();
299 int N = A.getType().getX();
300 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_cgemv, TransA, 0, 0, 0, 0, M, N, 0, alpha.x, alpha.y, A.getID(mRS), X.getID(mRS), beta.x, beta.y, Y.getID(mRS), incX, incY, 0, 0);
301 }
302 void ZGEMV(@Transpose int TransA, Double2 alpha, Allocation A, Allocation X, int incX, Double2 beta, Allocation Y, int incY) {
303 validateGEMV(Element.F64_2(mRS), TransA, A, X, incX, Y, incY);
304 int M = A.getType().getY();
305 int N = A.getType().getX();
306 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zgemv, TransA, 0, 0, 0, 0, M, N, 0, alpha.x, alpha.y, A.getID(mRS), X.getID(mRS), beta.x, beta.y, Y.getID(mRS), incX, incY, 0, 0);
307 }
308
309 void SGBMV(@Transpose int TransA, int KL, int KU, float alpha, Allocation A, Allocation X, int incX, float beta, Allocation Y, int incY) {
310 // GBMV has the same validation requirements as GEMV + KL and KU >= 0
311 validateGEMV(Element.F32(mRS), TransA, A, X, incX, Y, incY);
312 if (KL < 0 || KU < 0) {
313 throw new RSRuntimeException("KL and KU must be greater than or equal to 0");
314 }
315 int M = A.getType().getY();
316 int N = A.getType().getX();
317 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_sgbmv, TransA, 0, 0, 0, 0, M, N, 0, alpha, A.getID(mRS), X.getID(mRS), beta, Y.getID(mRS), incX, incY, KL, KU);
318 }
319 void DGBMV(@Transpose int TransA, int KL, int KU, double alpha, Allocation A, Allocation X, int incX, double beta, Allocation Y, int incY) {
320 // GBMV has the same validation requirements as GEMV + KL and KU >= 0
321 validateGEMV(Element.F64(mRS), TransA, A, X, incX, Y, incY);
322 if (KL < 0 || KU < 0) {
323 throw new RSRuntimeException("KL and KU must be greater than or equal to 0");
324 }
325 int M = A.getType().getY();
326 int N = A.getType().getX();
327 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dgbmv, TransA, 0, 0, 0, 0, M, N, 0, alpha, A.getID(mRS), X.getID(mRS), beta, Y.getID(mRS), incX, incY, KL, KU);
328 }
329 void CGBMV(@Transpose int TransA, int KL, int KU, Float2 alpha, Allocation A, Allocation X, int incX, Float2 beta, Allocation Y, int incY) {
330 // GBMV has the same validation requirements as GEMV + KL and KU >= 0
331 validateGEMV(Element.F32_2(mRS), TransA, A, X, incX, Y, incY);
332 if (KL < 0 || KU < 0) {
333 throw new RSRuntimeException("KL and KU must be greater than or equal to 0");
334 }
335 int M = A.getType().getY();
336 int N = A.getType().getX();
337 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_cgbmv, TransA, 0, 0, 0, 0, M, N, 0, alpha.x, alpha.y, A.getID(mRS), X.getID(mRS), beta.x, beta.y, Y.getID(mRS), incX, incY, KL, KU);
338 }
339 void ZGBMV(@Transpose int TransA, int KL, int KU, Double2 alpha, Allocation A, Allocation X, int incX, Double2 beta, Allocation Y, int incY) {
340 // GBMV has the same validation requirements as GEMV + KL and KU >= 0
341 validateGEMV(Element.F64_2(mRS), TransA, A, X, incX, Y, incY);
342 if (KL < 0 || KU < 0) {
343 throw new RSRuntimeException("KL and KU must be greater than or equal to 0");
344 }
345 int M = A.getType().getY();
346 int N = A.getType().getX();
347 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zgbmv, TransA, 0, 0, 0, 0, M, N, 0, alpha.x, alpha.y, A.getID(mRS), X.getID(mRS), beta.x, beta.y, Y.getID(mRS), incX, incY, KL, KU);
348 }
349
Miao Wang2b6fad92015-04-23 15:06:09 -0700350 static void validateTRMV(Element e, @Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation A, Allocation X, int incX) {
Tim Murray25207df2015-01-12 16:47:56 -0800351 validateTranspose(TransA);
Miao Wang2b6fad92015-04-23 15:06:09 -0700352 validateUplo(Uplo);
353 validateDiag(Diag);
Tim Murray25207df2015-01-12 16:47:56 -0800354 int N = A.getType().getY();
355 if (A.getType().getX() != N) {
356 throw new RSRuntimeException("A must be a square matrix for TRMV");
357 }
358 if (!A.getType().getElement().isCompatible(e) ||
359 !X.getType().getElement().isCompatible(e)) {
360 throw new RSRuntimeException("Called BLAS with wrong Element type");
361 }
362 if (X.getType().getY() > 1) {
363 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
364 }
365
366 if (incX <= 0) {
367 throw new RSRuntimeException("Vector increments must be greater than 0");
368 }
369 int expectedXDim = 1 + (N - 1) * incX;
370 if (X.getType().getX() != expectedXDim) {
371 throw new RSRuntimeException("Incorrect vector dimensions for TRMV");
372 }
373 }
374
375 static int validateTPMV(Element e, @Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation Ap, Allocation X, int incX) {
376 validateTranspose(TransA);
377 validateUplo(Uplo);
378 validateDiag(Diag);
379 if (!Ap.getType().getElement().isCompatible(e) ||
380 !X.getType().getElement().isCompatible(e)) {
381 throw new RSRuntimeException("Called BLAS with wrong Element type");
382 }
383 if (X.getType().getY() > 1) {
384 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
385 }
386
387 if (Ap.getType().getY() > 1) {
388 throw new RSRuntimeException("Ap must have a Y dimension of 0 or 1");
389 }
390
391 int N = (int)Math.sqrt((double)Ap.getType().getX() * 2);
Miao Wang2b6fad92015-04-23 15:06:09 -0700392 //is it really doing anything?
Tim Murray25207df2015-01-12 16:47:56 -0800393 if (Ap.getType().getX() != ((N * (N+1)) / 2)) {
394 throw new RSRuntimeException("Invalid dimension for Ap");
395 }
Miao Wang2b6fad92015-04-23 15:06:09 -0700396 if (incX <= 0) {
397 throw new RSRuntimeException("Vector increments must be greater than 0");
398 }
Tim Murray25207df2015-01-12 16:47:56 -0800399 int expectedXDim = 1 + (N - 1) * incX;
400 if (X.getType().getX() != expectedXDim) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700401 throw new RSRuntimeException("Incorrect vector dimensions for TPMV");
Tim Murray25207df2015-01-12 16:47:56 -0800402 }
403
404 return N;
405 }
406
407 void STRMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700408 validateTRMV(Element.F32(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800409 int N = A.getType().getY();
410 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_strmv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
411 }
412 void DTRMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700413 validateTRMV(Element.F64(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800414 int N = A.getType().getY();
415 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dtrmv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
416 }
417 void CTRMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700418 validateTRMV(Element.F32_2(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800419 int N = A.getType().getY();
420 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_ctrmv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
421 }
422 void ZTRMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700423 validateTRMV(Element.F64_2(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800424 int N = A.getType().getY();
425 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_ztrmv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
426 }
Miao Wang2b6fad92015-04-23 15:06:09 -0700427
Tim Murray25207df2015-01-12 16:47:56 -0800428 void STBMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, int K, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700429 // TBMV has the same requirements as TRMV + K >= 0
430 if (K < 0) {
431 throw new RSRuntimeException("K must be greater than or equal to 0");
432 }
433 validateTRMV(Element.F32(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800434 int N = A.getType().getY();
435 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_stbmv, TransA, 0, 0, Uplo, Diag, 0, N, K, 0, A.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
436 }
437 void DTBMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, int K, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700438 // TBMV has the same requirements as TRMV + K >= 0
439 if (K < 0) {
440 throw new RSRuntimeException("K must be greater than or equal to 0");
441 }
442 validateTRMV(Element.F64(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800443 int N = A.getType().getY();
444 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dtbmv, TransA, 0, 0, Uplo, Diag, 0, N, K, 0, A.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
445 }
446 void CTBMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, int K, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700447 // TBMV has the same requirements as TRMV + K >= 0
448 if (K < 0) {
449 throw new RSRuntimeException("K must be greater than or equal to 0");
450 }
451 validateTRMV(Element.F32_2(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800452 int N = A.getType().getY();
453 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_ctbmv, TransA, 0, 0, Uplo, Diag, 0, N, K, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
454 }
455 void ZTBMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, int K, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700456 // TBMV has the same requirements as TRMV + K >= 0
457 if (K < 0) {
458 throw new RSRuntimeException("K must be greater than or equal to 0");
459 }
460 validateTRMV(Element.F64_2(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800461 int N = A.getType().getY();
462 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_ztbmv, TransA, 0, 0, Uplo, Diag, 0, N, K, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
463 }
464 void STPMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation Ap, Allocation X, int incX) {
465 int N = validateTPMV(Element.F32(mRS), Uplo, TransA, Diag, Ap, X, incX);
466 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_stpmv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, Ap.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
467 }
468 void DTPMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation Ap, Allocation X, int incX) {
469 int N = validateTPMV(Element.F64(mRS), Uplo, TransA, Diag, Ap, X, incX);
470 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dtpmv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, Ap.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
471 }
472 void CTPMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation Ap, Allocation X, int incX) {
473 int N = validateTPMV(Element.F32_2(mRS), Uplo, TransA, Diag, Ap, X, incX);
474 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_ctpmv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, 0, Ap.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
475 }
476 void ZTPMV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation Ap, Allocation X, int incX) {
477 int N = validateTPMV(Element.F64_2(mRS), Uplo, TransA, Diag, Ap, X, incX);
478 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_ztpmv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, 0, Ap.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
479 }
480 void STRSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation A, Allocation X, int incX) {
481 // TRSV is the same as TRMV
Miao Wang2b6fad92015-04-23 15:06:09 -0700482 validateTRMV(Element.F32(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800483 int N = A.getType().getY();
484 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_strsv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
485
486 }
487 void DTRSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation A, Allocation X, int incX) {
488 // TRSV is the same as TRMV
Miao Wang2b6fad92015-04-23 15:06:09 -0700489 validateTRMV(Element.F64(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800490 int N = A.getType().getY();
491 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dtrsv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
492
493 }
494 void CTRSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation A, Allocation X, int incX) {
495 // TRSV is the same as TRMV
Miao Wang2b6fad92015-04-23 15:06:09 -0700496 validateTRMV(Element.F32_2(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800497 int N = A.getType().getY();
498 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_ctrsv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
499
500 }
501 void ZTRSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation A, Allocation X, int incX) {
502 // TRSV is the same as TRMV
Miao Wang2b6fad92015-04-23 15:06:09 -0700503 validateTRMV(Element.F64_2(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800504 int N = A.getType().getY();
505 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_ztrsv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
506
507 }
508 void STBSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, int K, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700509 // TBSV is the same as TRMV + K >= 0
510 validateTRMV(Element.F32(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800511 int N = A.getType().getY();
512 if (K < 0) {
513 throw new RSRuntimeException("Number of diagonals must be positive");
514 }
515 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_stbsv, TransA, 0, 0, Uplo, Diag, 0, N, K, 0, A.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
516 }
517 void DTBSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, int K, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700518 // TBSV is the same as TRMV + K >= 0
519 validateTRMV(Element.F64(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800520 int N = A.getType().getY();
521 if (K < 0) {
522 throw new RSRuntimeException("Number of diagonals must be positive");
523 }
524 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dtbsv, TransA, 0, 0, Uplo, Diag, 0, N, K, 0, A.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
525 }
526 void CTBSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, int K, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700527 // TBSV is the same as TRMV + K >= 0
528 validateTRMV(Element.F32_2(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800529 int N = A.getType().getY();
530 if (K < 0) {
531 throw new RSRuntimeException("Number of diagonals must be positive");
532 }
533 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_ctbsv, TransA, 0, 0, Uplo, Diag, 0, N, K, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
534 }
535 void ZTBSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, int K, Allocation A, Allocation X, int incX) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700536 // TBSV is the same as TRMV + K >= 0
537 validateTRMV(Element.F64_2(mRS), Uplo, TransA, Diag, A, X, incX);
Tim Murray25207df2015-01-12 16:47:56 -0800538 int N = A.getType().getY();
539 if (K < 0) {
540 throw new RSRuntimeException("Number of diagonals must be positive");
541 }
542 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_ztbsv, TransA, 0, 0, Uplo, Diag, 0, N, K, 0, 0, A.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
543 }
544 void STPSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation Ap, Allocation X, int incX) {
545 // TPSV is same as TPMV
546 int N = validateTPMV(Element.F32(mRS), Uplo, TransA, Diag, Ap, X, incX);
547 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_stpsv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, Ap.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
548 }
549 void DTPSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation Ap, Allocation X, int incX) {
550 // TPSV is same as TPMV
551 int N = validateTPMV(Element.F64(mRS), Uplo, TransA, Diag, Ap, X, incX);
552 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dtpsv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, Ap.getID(mRS), X.getID(mRS), 0, 0, incX, 0, 0, 0);
553 }
554 void CTPSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation Ap, Allocation X, int incX) {
555 // TPSV is same as TPMV
556 int N = validateTPMV(Element.F32_2(mRS), Uplo, TransA, Diag, Ap, X, incX);
557 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_ctpsv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, 0, Ap.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
558 }
559 void ZTPSV(@Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Allocation Ap, Allocation X, int incX) {
560 // TPSV is same as TPMV
561 int N = validateTPMV(Element.F64_2(mRS), Uplo, TransA, Diag, Ap, X, incX);
562 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_ztpsv, TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, 0, Ap.getID(mRS), X.getID(mRS), 0, 0, 0, incX, 0, 0, 0);
563 }
564
565 /**
566 * Level 2, S and D only
567 */
568 static int validateSYMV(Element e, @Uplo int Uplo, Allocation A, Allocation X, Allocation Y, int incX, int incY) {
569 validateUplo(Uplo);
570 int N = A.getType().getY();
571 if (A.getType().getX() != N) {
572 throw new RSRuntimeException("A must be a square matrix for SYMV");
573 }
574 if (!A.getType().getElement().isCompatible(e) ||
575 !X.getType().getElement().isCompatible(e) ||
576 !Y.getType().getElement().isCompatible(e) ) {
577 throw new RSRuntimeException("Called BLAS with wrong Element type");
578 }
579 if (X.getType().getY() > 1 || Y.getType().getY() > 1) {
580 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
581 }
582
583 if (incX <= 0 || incY <= 0) {
584 throw new RSRuntimeException("Vector increments must be greater than 0");
585 }
586 int expectedXDim = 1 + (N - 1) * incX;
587 if (X.getType().getX() != expectedXDim) {
588 throw new RSRuntimeException("Incorrect vector dimensions for SYMV");
589 }
590 int expectedYDim = 1 + (N - 1) * incY;
591 if (Y.getType().getX() != expectedYDim) {
592 throw new RSRuntimeException("Incorrect vector dimensions for SYMV");
593 }
594 return N;
595 }
596 static int validateSPMV(Element e, @Uplo int Uplo, Allocation Ap, Allocation X, int incX, Allocation Y, int incY) {
597 validateUplo(Uplo);
598 if (!Ap.getType().getElement().isCompatible(e) ||
599 !X.getType().getElement().isCompatible(e) ||
600 !Y.getType().getElement().isCompatible(e)) {
601 throw new RSRuntimeException("Called BLAS with wrong Element type");
602 }
603 if (X.getType().getY() > 1 || Y.getType().getY() > 1) {
604 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
605 }
606
607 if (Ap.getType().getY() > 1) {
608 throw new RSRuntimeException("Ap must have a Y dimension of 0 or 1");
609 }
610
611 int N = (int)Math.sqrt((double)Ap.getType().getX() * 2);
612 if (Ap.getType().getX() != ((N * (N+1)) / 2)) {
613 throw new RSRuntimeException("Invalid dimension for Ap");
614 }
Miao Wang2b6fad92015-04-23 15:06:09 -0700615 if (incX <= 0 || incY <= 0) {
616 throw new RSRuntimeException("Vector increments must be greater than 0");
617 }
Tim Murray25207df2015-01-12 16:47:56 -0800618 int expectedXDim = 1 + (N - 1) * incX;
619 if (X.getType().getX() != expectedXDim) {
620 throw new RSRuntimeException("Incorrect vector dimensions for SPMV");
621 }
622 int expectedYDim = 1 + (N - 1) * incY;
623 if (Y.getType().getX() != expectedYDim) {
624 throw new RSRuntimeException("Incorrect vector dimensions for SPMV");
625 }
626
627 return N;
628 }
629 static void validateGER(Element e, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
630 if (!A.getType().getElement().isCompatible(e) ||
631 !X.getType().getElement().isCompatible(e) ||
632 !Y.getType().getElement().isCompatible(e) ) {
633 throw new RSRuntimeException("Called BLAS with wrong Element type");
634 }
635
636 if (X.getType().getY() > 1 || Y.getType().getY() > 1) {
637 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
638 }
639
640 int M = A.getType().getY();
641 int N = A.getType().getX();
642
643 if (N < 1 || M < 1) {
644 throw new RSRuntimeException("M and N must be 1 or greater for GER");
645 }
Miao Wang2b6fad92015-04-23 15:06:09 -0700646 if (incX <= 0 || incY <= 0) {
647 throw new RSRuntimeException("Vector increments must be greater than 0");
648 }
649 int expectedXDim = 1 + (M - 1) * incX;
Tim Murray25207df2015-01-12 16:47:56 -0800650 if (X.getType().getX() != expectedXDim) {
651 throw new RSRuntimeException("Incorrect vector dimensions for GER");
652 }
653 int expectedYDim = 1 + (N - 1) * incY;
654 if (Y.getType().getX() != expectedYDim) {
655 throw new RSRuntimeException("Incorrect vector dimensions for GER");
656 }
657
658
659 }
660 static int validateSYR(Element e, @Uplo int Uplo, Allocation X, int incX, Allocation A) {
661 validateUplo(Uplo);
662 if (!A.getType().getElement().isCompatible(e) ||
663 !X.getType().getElement().isCompatible(e)) {
664 throw new RSRuntimeException("Called BLAS with wrong Element type");
665 }
666
667 int N = A.getType().getX();
668
669 if (X.getType().getY() > 1) {
670 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
671 }
672 if (N != A.getType().getY()) {
673 throw new RSRuntimeException("A must be a symmetric matrix");
674 }
Miao Wang2b6fad92015-04-23 15:06:09 -0700675 if (incX <= 0) {
676 throw new RSRuntimeException("Vector increments must be greater than 0");
677 }
Tim Murray25207df2015-01-12 16:47:56 -0800678 int expectedXDim = 1 + (N - 1) * incX;
679 if (X.getType().getX() != expectedXDim) {
680 throw new RSRuntimeException("Incorrect vector dimensions for SYR");
681 }
682 return N;
683 }
684 static int validateSPR(Element e, @Uplo int Uplo, Allocation X, int incX, Allocation Ap) {
685 validateUplo(Uplo);
686 if (!Ap.getType().getElement().isCompatible(e) ||
687 !X.getType().getElement().isCompatible(e)) {
688 throw new RSRuntimeException("Called BLAS with wrong Element type");
689 }
690 if (X.getType().getY() > 1) {
691 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
692 }
693
694 if (Ap.getType().getY() > 1) {
695 throw new RSRuntimeException("Ap must have a Y dimension of 0 or 1");
696 }
697
698 int N = (int)Math.sqrt((double)Ap.getType().getX() * 2);
699 if (Ap.getType().getX() != ((N * (N+1)) / 2)) {
700 throw new RSRuntimeException("Invalid dimension for Ap");
701 }
Miao Wang2b6fad92015-04-23 15:06:09 -0700702 if (incX <= 0) {
703 throw new RSRuntimeException("Vector increments must be greater than 0");
704 }
Tim Murray25207df2015-01-12 16:47:56 -0800705 int expectedXDim = 1 + (N - 1) * incX;
706 if (X.getType().getX() != expectedXDim) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700707 throw new RSRuntimeException("Incorrect vector dimensions for SPR");
Tim Murray25207df2015-01-12 16:47:56 -0800708 }
709
710 return N;
711 }
712
713 static int validateSYR2(Element e, @Uplo int Uplo, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
714 validateUplo(Uplo);
715 if (!A.getType().getElement().isCompatible(e) ||
716 !X.getType().getElement().isCompatible(e) ||
717 !Y.getType().getElement().isCompatible(e)) {
718 throw new RSRuntimeException("Called BLAS with wrong Element type");
719 }
720
721 if (X.getType().getY() > 1 || Y.getType().getY() > 1) {
722 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
723 }
724
725 int N = A.getType().getX();
726
727 if (N != A.getType().getY()) {
728 throw new RSRuntimeException("A must be a symmetric matrix");
729 }
Miao Wang2b6fad92015-04-23 15:06:09 -0700730 if (incX <= 0 || incY <= 0) {
731 throw new RSRuntimeException("Vector increments must be greater than 0");
732 }
Tim Murray25207df2015-01-12 16:47:56 -0800733 int expectedXDim = 1 + (N - 1) * incX;
734 int expectedYDim = 1 + (N - 1) * incY;
735 if (X.getType().getX() != expectedXDim || Y.getType().getX() != expectedYDim) {
736 throw new RSRuntimeException("Incorrect vector dimensions for SYR");
737 }
738 return N;
739
740 }
741 static int validateSPR2(Element e, @Uplo int Uplo, Allocation X, int incX, Allocation Y, int incY, Allocation Ap) {
742 validateUplo(Uplo);
743 if (!Ap.getType().getElement().isCompatible(e) ||
744 !X.getType().getElement().isCompatible(e) ||
745 !Y.getType().getElement().isCompatible(e)) {
746 throw new RSRuntimeException("Called BLAS with wrong Element type");
747 }
748 if (X.getType().getY() > 1 || Y.getType().getY() > 1) {
749 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
750 }
751
752 if (Ap.getType().getY() > 1) {
753 throw new RSRuntimeException("Ap must have a Y dimension of 0 or 1");
754 }
755
756 int N = (int)Math.sqrt((double)Ap.getType().getX() * 2);
757 if (Ap.getType().getX() != ((N * (N+1)) / 2)) {
758 throw new RSRuntimeException("Invalid dimension for Ap");
759 }
Miao Wang2b6fad92015-04-23 15:06:09 -0700760 if (incX <= 0 || incY <= 0) {
761 throw new RSRuntimeException("Vector increments must be greater than 0");
762 }
Tim Murray25207df2015-01-12 16:47:56 -0800763 int expectedXDim = 1 + (N - 1) * incX;
764 int expectedYDim = 1 + (N - 1) * incY;
765 if (X.getType().getX() != expectedXDim || Y.getType().getX() != expectedYDim) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700766 throw new RSRuntimeException("Incorrect vector dimensions for SPR2");
Tim Murray25207df2015-01-12 16:47:56 -0800767 }
768
769 return N;
770 }
771
772 void SSYMV(@Uplo int Uplo, float alpha, Allocation A, Allocation X, int incX, float beta, Allocation Y, int incY) {
773 int N = validateSYMV(Element.F32(mRS), Uplo, A, X, Y, incX, incY);
774 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_ssymv, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, A.getID(mRS), X.getID(mRS), beta, Y.getID(mRS), incX, incY, 0, 0);
775 }
776 void SSBMV(@Uplo int Uplo, int K, float alpha, Allocation A, Allocation X, int incX, float beta, Allocation Y, int incY) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700777 // SBMV is the same as SYMV + K >= 0
778 if (K < 0) {
779 throw new RSRuntimeException("K must be greater than or equal to 0");
780 }
Tim Murray25207df2015-01-12 16:47:56 -0800781 int N = validateSYMV(Element.F32(mRS), Uplo, A, X, Y, incX, incY);
782 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_ssbmv, 0, 0, 0, Uplo, 0, 0, N, K, alpha, A.getID(mRS), X.getID(mRS), beta, Y.getID(mRS), incX, incY, 0, 0);
783 }
784 void SSPMV(@Uplo int Uplo, float alpha, Allocation Ap, Allocation X, int incX, float beta, Allocation Y, int incY) {
785 int N = validateSPMV(Element.F32(mRS), Uplo, Ap, X, incX, Y, incY);
786 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_sspmv, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, Ap.getID(mRS), X.getID(mRS), beta, Y.getID(mRS), incX, incY, 0, 0);
787 }
788 void SGER(float alpha, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
789 int M = A.getType().getY();
790 int N = A.getType().getX();
Miao Wang2b6fad92015-04-23 15:06:09 -0700791 validateGER(Element.F32(mRS), X, incX, Y, incY, A);
Tim Murray25207df2015-01-12 16:47:56 -0800792 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_sger, 0, 0, 0, 0, 0, M, N, 0, alpha, X.getID(mRS), Y.getID(mRS), 0.f, A.getID(mRS), incX, incY, 0, 0);
793 }
794 void SSYR(@Uplo int Uplo, float alpha, Allocation X, int incX, Allocation A) {
795 int N = validateSYR(Element.F32(mRS), Uplo, X, incX, A);
796 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_ssyr, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, X.getID(mRS), A.getID(mRS), 0.f, 0, incX, 0, 0, 0);
797 }
798 void SSPR(@Uplo int Uplo, float alpha, Allocation X, int incX, Allocation Ap) {
799 int N = validateSPR(Element.F32(mRS), Uplo, X, incX, Ap);
800 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_sspr, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, X.getID(mRS), Ap.getID(mRS), 0.f, 0, incX, 0, 0, 0);
801 }
802 void SSYR2(@Uplo int Uplo, float alpha, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
803 int N = validateSYR2(Element.F32(mRS), Uplo, X, incX, Y, incY, A);
804 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_ssyr2, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, X.getID(mRS), Y.getID(mRS), 0, A.getID(mRS), incX, incY, 0, 0);
805 }
806 void SSPR2(@Uplo int Uplo, float alpha, Allocation X, int incX, Allocation Y, int incY, Allocation Ap) {
807 int N = validateSPR2(Element.F32(mRS), Uplo, X, incX, Y, incY, Ap);
808 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_sspr2, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, X.getID(mRS), Y.getID(mRS), 0, Ap.getID(mRS), incX, incY, 0, 0);
809 }
810 void DSYMV(@Uplo int Uplo, double alpha, Allocation A, Allocation X, int incX, double beta, Allocation Y, int incY) {
811 int N = validateSYMV(Element.F64(mRS), Uplo, A, X, Y, incX, incY);
812 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dsymv, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, A.getID(mRS), X.getID(mRS), beta, Y.getID(mRS), incX, incY, 0, 0);
813 }
814 void DSBMV(@Uplo int Uplo, int K, double alpha, Allocation A, Allocation X, int incX, double beta, Allocation Y, int incY) {
Miao Wang2b6fad92015-04-23 15:06:09 -0700815 // SBMV is the same as SYMV + K >= 0
816 if (K < 0) {
817 throw new RSRuntimeException("K must be greater than or equal to 0");
818 }
Tim Murray25207df2015-01-12 16:47:56 -0800819 int N = validateSYMV(Element.F64(mRS), Uplo, A, X, Y, incX, incY);
820 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dsbmv, 0, 0, 0, Uplo, 0, 0, N, K, alpha, A.getID(mRS), X.getID(mRS), beta, Y.getID(mRS), incX, incY, 0, 0);
821 }
822 void DSPMV(@Uplo int Uplo, double alpha, Allocation Ap, Allocation X, int incX, double beta, Allocation Y, int incY) {
823 int N = validateSPMV(Element.F64(mRS), Uplo, Ap, X, incX, Y, incY);
824 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dspmv, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, Ap.getID(mRS), X.getID(mRS), beta, Y.getID(mRS), incX, incY, 0, 0);
825 }
826 void DGER(double alpha, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
827 int M = A.getType().getY();
828 int N = A.getType().getX();
Miao Wang2b6fad92015-04-23 15:06:09 -0700829 validateGER(Element.F64(mRS), X, incX, Y, incY, A);
Tim Murray25207df2015-01-12 16:47:56 -0800830 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dger, 0, 0, 0, 0, 0, M, N, 0, alpha, X.getID(mRS), Y.getID(mRS), 0.f, A.getID(mRS), incX, incY, 0, 0);
831 }
832 void DSYR(@Uplo int Uplo, double alpha, Allocation X, int incX, Allocation A) {
833 int N = validateSYR(Element.F64(mRS), Uplo, X, incX, A);
834 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dsyr, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, X.getID(mRS), A.getID(mRS), 0.f, 0, incX, 0, 0, 0);
835 }
836 void DSPR(@Uplo int Uplo, double alpha, Allocation X, int incX, Allocation Ap) {
837 int N = validateSPR(Element.F64(mRS), Uplo, X, incX, Ap);
838 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dspr, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, X.getID(mRS), Ap.getID(mRS), 0.f, 0, incX, 0, 0, 0);
839 }
840 void DSYR2(@Uplo int Uplo, double alpha, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
841 int N = validateSYR2(Element.F64(mRS), Uplo, X, incX, Y, incY, A);
842 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dsyr2, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, X.getID(mRS), Y.getID(mRS), 0, A.getID(mRS), incX, incY, 0, 0);
843 }
844 void DSPR2(@Uplo int Uplo, double alpha, Allocation X, int incX, Allocation Y, int incY, Allocation Ap) {
845 int N = validateSPR2(Element.F64(mRS), Uplo, X, incX, Y, incY, Ap);
846 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dspr2, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, X.getID(mRS), Y.getID(mRS), 0, Ap.getID(mRS), incX, incY, 0, 0);
847 }
848
849
850 /**
851 * Level 2, C and Z only
852 */
853
854 static void validateGERU(Element e, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
855 if (!A.getType().getElement().isCompatible(e) ||
856 !X.getType().getElement().isCompatible(e) ||
857 !Y.getType().getElement().isCompatible(e)) {
858 throw new RSRuntimeException("Called BLAS with wrong Element type");
859 }
860 if (X.getType().getY() > 1 || Y.getType().getY() > 1) {
861 throw new RSRuntimeException("BLAS vectors must have Y dimension of 0 or 1");
862 }
863
864 int M = A.getType().getY();
865 int N = A.getType().getX();
Miao Wang2b6fad92015-04-23 15:06:09 -0700866 if (incX <= 0 || incY <= 0) {
867 throw new RSRuntimeException("Vector increments must be greater than 0");
868 }
869 int expectedXDim = 1 + (M - 1) * incX;
Tim Murray25207df2015-01-12 16:47:56 -0800870 if (X.getType().getX() != expectedXDim) {
871 throw new RSRuntimeException("Incorrect vector dimensions for GERU");
872 }
873 int expectedYDim = 1 + (N - 1) * incY;
874 if (Y.getType().getX() != expectedYDim) {
875 throw new RSRuntimeException("Incorrect vector dimensions for GERU");
876 }
877
878 }
879
880 void CHEMV(@Uplo int Uplo, Float2 alpha, Allocation A, Allocation X, int incX, Float2 beta, Allocation Y, int incY) {
881 // HEMV is the same as SYR2 validation-wise
882 int N = validateSYR2(Element.F32_2(mRS), Uplo, X, incX, Y, incY, A);
883 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_chemv, 0, 0, 0, Uplo, 0, 0, N, 0, alpha.x, alpha.y, A.getID(mRS), X.getID(mRS), beta.x, beta.y, Y.getID(mRS), incX, incY, 0, 0);
884 }
885 void CHBMV(@Uplo int Uplo, int K, Float2 alpha, Allocation A, Allocation X, int incX, Float2 beta, Allocation Y, int incY) {
886 // HBMV is the same as SYR2 validation-wise
887 int N = validateSYR2(Element.F32_2(mRS), Uplo, X, incX, Y, incY, A);
888 if (K < 0) {
889 throw new RSRuntimeException("K must be 0 or greater for HBMV");
890 }
891 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_chbmv, 0, 0, 0, Uplo, 0, 0, N, K, alpha.x, alpha.y, A.getID(mRS), X.getID(mRS), beta.x, beta.y, Y.getID(mRS), incX, incY, 0, 0);
892 }
893 void CHPMV(@Uplo int Uplo, Float2 alpha, Allocation Ap, Allocation X, int incX, Float2 beta, Allocation Y, int incY) {
894 // HPMV is the same as SPR2
895 int N = validateSPR2(Element.F32_2(mRS), Uplo, X, incX, Y, incY, Ap);
896 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_chpmv, 0, 0, 0, Uplo, 0, 0, N, 0, alpha.x, alpha.y, Ap.getID(mRS), X.getID(mRS), beta.x, beta.y, Y.getID(mRS), incX, incY, 0, 0);
897 }
898 void CGERU(Float2 alpha, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
899 validateGERU(Element.F32_2(mRS), X, incX, Y, incY, A);
900 int M = A.getType().getY();
901 int N = A.getType().getX();
902 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_cgeru, 0, 0, 0, 0, 0, M, N, 0, alpha.x, alpha.y, X.getID(mRS), Y.getID(mRS), 0, 0, A.getID(mRS), incX, incY, 0, 0);
903 }
904 void CGERC(Float2 alpha, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
905 // same as GERU
906 validateGERU(Element.F32_2(mRS), X, incX, Y, incY, A);
907 int M = A.getType().getY();
908 int N = A.getType().getX();
909 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_cgerc, 0, 0, 0, 0, 0, M, N, 0, alpha.x, alpha.y, X.getID(mRS), Y.getID(mRS), 0, 0, A.getID(mRS), incX, incY, 0, 0);
910 }
911 void CHER(@Uplo int Uplo, float alpha, Allocation X, int incX, Allocation A) {
912 // same as SYR
Miao Wang2b6fad92015-04-23 15:06:09 -0700913 int N = validateSYR(Element.F32_2(mRS), Uplo, X, incX, A);
Tim Murray25207df2015-01-12 16:47:56 -0800914 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_cher, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, 0, X.getID(mRS), 0, 0, 0, A.getID(mRS), incX, 0, 0, 0);
915 }
916 void CHPR(@Uplo int Uplo, float alpha, Allocation X, int incX, Allocation Ap) {
917 // equivalent to SPR for validation
918 int N = validateSPR(Element.F32_2(mRS), Uplo, X, incX, Ap);
919 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_chpr, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, 0, X.getID(mRS), 0, 0, 0, Ap.getID(mRS), incX, 0, 0, 0);
920 }
921 void CHER2(@Uplo int Uplo, Float2 alpha, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
922 // same as SYR2
923 int N = validateSYR2(Element.F32_2(mRS), Uplo, X, incX, Y, incY, A);
924 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_cher2, 0, 0, 0, Uplo, 0, 0, N, 0, alpha.x, alpha.y, X.getID(mRS), Y.getID(mRS), 0, 0, A.getID(mRS), incX, incY, 0, 0);
925 }
926 void CHPR2(@Uplo int Uplo, Float2 alpha, Allocation X, int incX, Allocation Y, int incY, Allocation Ap) {
927 // same as SPR2
928 int N = validateSPR2(Element.F32_2(mRS), Uplo, X, incX, Y, incY, Ap);
929 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_chpr2, 0, 0, 0, Uplo, 0, 0, N, 0, alpha.x, alpha.y, X.getID(mRS), Y.getID(mRS), 0, 0, Ap.getID(mRS), incX, incY, 0, 0);
930 }
931 void ZHEMV(@Uplo int Uplo, Double2 alpha, Allocation A, Allocation X, int incX, Double2 beta, Allocation Y, int incY) {
932 // HEMV is the same as SYR2 validation-wise
933 int N = validateSYR2(Element.F64_2(mRS), Uplo, X, incX, Y, incY, A);
934 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zhemv, 0, 0, 0, Uplo, 0, 0, N, 0, alpha.x, alpha.y, A.getID(mRS), X.getID(mRS), beta.x, beta.y, Y.getID(mRS), incX, incY, 0, 0);
935 }
936 void ZHBMV(@Uplo int Uplo, int K, Double2 alpha, Allocation A, Allocation X, int incX, Double2 beta, Allocation Y, int incY) {
937 // HBMV is the same as SYR2 validation-wise
938 int N = validateSYR2(Element.F64_2(mRS), Uplo, X, incX, Y, incY, A);
939 if (K < 0) {
940 throw new RSRuntimeException("K must be 0 or greater for HBMV");
941 }
942 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zhbmv, 0, 0, 0, Uplo, 0, 0, N, K, alpha.x, alpha.y, A.getID(mRS), X.getID(mRS), beta.x, beta.y, Y.getID(mRS), incX, incY, 0, 0);
943 }
944 void ZHPMV(@Uplo int Uplo, Double2 alpha, Allocation Ap, Allocation X, int incX, Double2 beta, Allocation Y, int incY) {
945 // HPMV is the same as SPR2
946 int N = validateSPR2(Element.F64_2(mRS), Uplo, X, incX, Y, incY, Ap);
947 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zhpmv, 0, 0, 0, Uplo, 0, 0, N, 0, alpha.x, alpha.y, Ap.getID(mRS), X.getID(mRS), beta.x, beta.y, Y.getID(mRS), incX, incY, 0, 0);
948 }
949 void ZGERU(Double2 alpha, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
950 validateGERU(Element.F64_2(mRS), X, incX, Y, incY, A);
951 int M = A.getType().getY();
952 int N = A.getType().getX();
953 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zgeru, 0, 0, 0, 0, 0, M, N, 0, alpha.x, alpha.y, X.getID(mRS), Y.getID(mRS), 0, 0, A.getID(mRS), incX, incY, 0, 0);
954 }
955 void ZGERC(Double2 alpha, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
956 // same as GERU
957 validateGERU(Element.F64_2(mRS), X, incX, Y, incY, A);
958 int M = A.getType().getY();
959 int N = A.getType().getX();
960 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zgerc, 0, 0, 0, 0, 0, M, N, 0, alpha.x, alpha.y, X.getID(mRS), Y.getID(mRS), 0, 0, A.getID(mRS), incX, incY, 0, 0);
961 }
962 void ZHER(@Uplo int Uplo, double alpha, Allocation X, int incX, Allocation A) {
963 // same as SYR
964 int N = validateSYR(Element.F64(mRS), Uplo, X, incX, A);
965 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zher, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, 0, X.getID(mRS), 0, 0, 0, A.getID(mRS), incX, 0, 0, 0);
966 }
967 void ZHPR(@Uplo int Uplo, double alpha, Allocation X, int incX, Allocation Ap) {
968 // equivalent to SPR for validation
969 int N = validateSPR(Element.F64_2(mRS), Uplo, X, incX, Ap);
970 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zhpr, 0, 0, 0, Uplo, 0, 0, N, 0, alpha, 0, X.getID(mRS), 0, 0, 0, Ap.getID(mRS), incX, 0, 0, 0);
971 }
972 void ZHER2(@Uplo int Uplo, Double2 alpha, Allocation X, int incX, Allocation Y, int incY, Allocation A) {
973 // same as SYR2
974 int N = validateSYR2(Element.F64_2(mRS), Uplo, X, incX, Y, incY, A);
975 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zher2, 0, 0, 0, Uplo, 0, 0, N, 0, alpha.x, alpha.y, X.getID(mRS), Y.getID(mRS), 0, 0, A.getID(mRS), incX, incY, 0, 0);
976 }
977 void ZHPR2(@Uplo int Uplo, Double2 alpha, Allocation X, int incX, Allocation Y, int incY, Allocation Ap) {
978 // same as SPR2
979 int N = validateSPR2(Element.F64_2(mRS), Uplo, X, incX, Y, incY, Ap);
980 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zhpr2, 0, 0, 0, Uplo, 0, 0, N, 0, alpha.x, alpha.y, X.getID(mRS), Y.getID(mRS), 0, 0, Ap.getID(mRS), incX, incY, 0, 0);
981 }
982
983
984 /**
985 * Level 3 BLAS
986 */
987
988 static void validateL3(Element e, int TransA, int TransB, int Side, Allocation A, Allocation B, Allocation C) {
989 int aX = -1, aY = -1, bX = -1, bY = -1, cX = -1, cY = -1;
990 if ((A != null && !A.getType().getElement().isCompatible(e)) ||
991 (B != null && !B.getType().getElement().isCompatible(e)) ||
992 (C != null && !C.getType().getElement().isCompatible(e))) {
993 throw new RSRuntimeException("Called BLAS with wrong Element type");
994 }
995 if (C != null) {
996 cX = C.getType().getY();
997 cY = C.getType().getX();
998 }
999 if (Side == RIGHT) {
1000 if (B != null) {
1001 bX = A.getType().getY();
1002 bY = A.getType().getX();
1003 }
1004 if (A != null) {
1005 aX = B.getType().getY();
1006 aY = B.getType().getX();
1007 }
1008 } else {
1009 if (A != null) {
1010 if (TransA == TRANSPOSE) {
1011 aY = A.getType().getY();
1012 aX = A.getType().getX();
1013 } else {
1014 aX = A.getType().getY();
1015 aY = A.getType().getX();
1016 }
1017 }
1018 if (B != null) {
1019 if (TransB == TRANSPOSE) {
1020 bY = B.getType().getY();
1021 bX = B.getType().getX();
1022 } else {
1023 bX = B.getType().getY();
1024 bY = B.getType().getX();
1025 }
1026 }
1027 }
1028 if (A != null && B != null && C != null) {
1029 if (aY != bX || aX != cX || bY != cY) {
1030 throw new RSRuntimeException("Called BLAS with invalid dimensions");
1031 }
1032 } else if (A != null && C != null) {
1033 // A and C only
1034 if (aX != cY || aY != cX) {
1035 throw new RSRuntimeException("Called BLAS with invalid dimensions");
1036 }
1037 } else if (A != null && B != null) {
1038 // A and B only
1039 }
1040
1041 }
1042
1043 public void SGEMM(@Transpose int TransA, @Transpose int TransB, float alpha, Allocation A,
1044 Allocation B, float beta, Allocation C) {
1045 validateTranspose(TransA);
1046 validateTranspose(TransB);
1047 validateL3(Element.F32(mRS), TransA, TransB, 0, A, B, C);
1048
1049 int M = -1, N = -1, K = -1;
1050 if (TransA == TRANSPOSE) {
1051 M = A.getType().getX();
1052 K = A.getType().getY();
1053 } else {
1054 M = A.getType().getY();
1055 K = A.getType().getX();
1056 }
1057 if (TransB == TRANSPOSE) {
1058 N = B.getType().getY();
1059 } else {
1060 N = B.getType().getX();
1061 }
1062 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_sgemm, TransA, TransB, 0, 0, 0, M, N, K, alpha, A.getID(mRS), B.getID(mRS),
1063 beta, C.getID(mRS), 0, 0, 0, 0);
1064 }
1065 public void DGEMM(@Transpose int TransA, @Transpose int TransB, double alpha, Allocation A,
1066 Allocation B, double beta, Allocation C) {
1067 validateTranspose(TransA);
1068 validateTranspose(TransB);
1069 validateL3(Element.F64(mRS), TransA, TransB, 0, A, B, C);
1070 int M = -1, N = -1, K = -1;
1071 if (TransA == TRANSPOSE) {
1072 M = A.getType().getX();
1073 K = A.getType().getY();
1074 } else {
1075 M = A.getType().getY();
1076 K = A.getType().getX();
1077 }
1078 if (TransB == TRANSPOSE) {
1079 N = B.getType().getY();
1080 } else {
1081 N = B.getType().getX();
1082 }
1083 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dgemm, TransA, TransB, 0, 0, 0, M, N, K, alpha, A.getID(mRS), B.getID(mRS),
1084 beta, C.getID(mRS), 0, 0, 0, 0);
1085 }
1086 public void CGEMM(@Transpose int TransA, @Transpose int TransB, Float2 alpha, Allocation A,
1087 Allocation B, Float2 beta, Allocation C) {
1088 validateTranspose(TransA);
1089 validateTranspose(TransB);
1090 validateL3(Element.F32_2(mRS), TransA, TransB, 0, A, B, C);
1091 int M = -1, N = -1, K = -1;
1092 if (TransA == TRANSPOSE) {
1093 M = A.getType().getX();
1094 K = A.getType().getY();
1095 } else {
1096 M = A.getType().getY();
1097 K = A.getType().getX();
1098 }
1099 if (TransB == TRANSPOSE) {
1100 N = B.getType().getY();
1101 } else {
1102 N = B.getType().getX();
1103 }
1104 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_cgemm, TransA, TransB, 0, 0, 0, M, N, K, alpha.x, alpha.y, A.getID(mRS), B.getID(mRS),
1105 beta.x, beta.y, C.getID(mRS), 0, 0, 0, 0);
1106 }
1107
1108 public void ZGEMM(@Transpose int TransA, @Transpose int TransB, Double2 alpha, Allocation A,
1109 Allocation B, Double2 beta, Allocation C) {
1110 validateTranspose(TransA);
1111 validateTranspose(TransB);
1112 validateL3(Element.F64_2(mRS), TransA, TransB, 0, A, B, C);
1113 int M = -1, N = -1, K = -1;
1114 if (TransA == TRANSPOSE) {
1115 M = A.getType().getX();
1116 K = A.getType().getY();
1117 } else {
1118 M = A.getType().getY();
1119 K = A.getType().getX();
1120 }
1121 if (TransB == TRANSPOSE) {
1122 N = B.getType().getY();
1123 } else {
1124 N = B.getType().getX();
1125 }
1126 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zgemm, TransA, TransB, 0, 0, 0, M, N, K, alpha.x, alpha.y, A.getID(mRS), B.getID(mRS),
1127 beta.x, beta.y, C.getID(mRS), 0, 0, 0, 0);
1128 }
1129
1130 public void SSYMM(@Side int Side, @Uplo int Uplo, float alpha, Allocation A,
1131 Allocation B, float beta, Allocation C) {
1132 validateSide(Side);
1133 validateUplo(Uplo);
1134 validateL3(Element.F32(mRS), 0, 0, Side, A, B, C);
1135 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_ssymm, 0, 0, Side, Uplo, 0, C.getType().getY(), C.getType().getX(), 0, alpha, A.getID(mRS), B.getID(mRS),
1136 beta, C.getID(mRS), 0, 0, 0, 0);
1137 }
1138 public void DSYMM(@Side int Side, @Uplo int Uplo, double alpha, Allocation A,
1139 Allocation B, double beta, Allocation C) {
1140 validateSide(Side);
1141 validateUplo(Uplo);
1142 validateL3(Element.F64(mRS), 0, 0, Side, A, B, C);
1143 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dsymm, 0, 0, Side, Uplo, 0, C.getType().getY(), C.getType().getX(), 0, alpha, A.getID(mRS), B.getID(mRS),
1144 beta, C.getID(mRS), 0, 0, 0, 0);
1145 }
1146 public void CSYMM(@Side int Side, @Uplo int Uplo, Float2 alpha, Allocation A,
1147 Allocation B, Float2 beta, Allocation C) {
1148 validateSide(Side);
1149 validateUplo(Uplo);
1150 validateL3(Element.F32_2(mRS), 0, 0, Side, A, B, C);
1151 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_csymm, 0, 0, Side, Uplo, 0, C.getType().getY(), C.getType().getX(), 0, alpha.x, alpha.y, A.getID(mRS), B.getID(mRS),
1152 beta.x, beta.y, C.getID(mRS), 0, 0, 0, 0);
1153 }
1154 public void ZSYMM(@Side int Side, @Uplo int Uplo, Double2 alpha, Allocation A,
1155 Allocation B, Double2 beta, Allocation C) {
1156 validateSide(Side);
1157 validateUplo(Uplo);
1158 validateL3(Element.F64_2(mRS), 0, 0, Side, A, B, C);
1159 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zsymm, 0, 0, Side, Uplo, 0, C.getType().getY(), C.getType().getX(), 0, alpha.x, alpha.y, A.getID(mRS), B.getID(mRS),
1160 beta.x, beta.y, C.getID(mRS), 0, 0, 0, 0);
1161 }
1162
1163 public void SSYRK(@Uplo int Uplo, @Transpose int Trans, float alpha, Allocation A, float beta, Allocation C) {
1164 validateTranspose(Trans);
1165 validateUplo(Uplo);
1166 validateL3(Element.F32(mRS), Trans, 0, 0, A, null, C);
1167 int K = -1;
1168 if (Trans == TRANSPOSE) {
1169 K = A.getType().getY();
1170 } else {
1171 K = A.getType().getX();
1172 }
1173
1174 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_ssyrk, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), K, alpha, A.getID(mRS), 0, beta, C.getID(mRS), 0, 0, 0, 0);
1175 }
1176
1177 public void DSYRK(@Uplo int Uplo, @Transpose int Trans, double alpha, Allocation A, double beta, Allocation C) {
1178 validateTranspose(Trans);
1179 validateUplo(Uplo);
1180 validateL3(Element.F64(mRS), Trans, 0, 0, A, null, C);
1181 int K = -1;
1182 if (Trans == TRANSPOSE) {
1183 K = A.getType().getY();
1184 } else {
1185 K = A.getType().getX();
1186 }
1187 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_dsyrk, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), K, alpha, A.getID(mRS), 0, beta, C.getID(mRS), 0, 0, 0, 0);
1188 }
Miao Wang333bcc02015-04-22 15:57:57 -07001189 public void CSYRK(@Uplo int Uplo, @Transpose int Trans, Float2 alpha, Allocation A, Float2 beta, Allocation C) {
Tim Murray25207df2015-01-12 16:47:56 -08001190 validateTranspose(Trans);
1191 validateUplo(Uplo);
1192 validateL3(Element.F32_2(mRS), Trans, 0, 0, A, null, C);
1193 int K = -1;
1194 if (Trans == TRANSPOSE) {
1195 K = A.getType().getY();
1196 } else {
1197 K = A.getType().getX();
1198 }
Miao Wang333bcc02015-04-22 15:57:57 -07001199 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_csyrk, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), K, alpha.x, alpha.y, A.getID(mRS), 0, beta.x, beta.y,
Tim Murray25207df2015-01-12 16:47:56 -08001200 C.getID(mRS), 0, 0, 0, 0);
1201 }
Miao Wang333bcc02015-04-22 15:57:57 -07001202 public void ZSYRK(@Uplo int Uplo, @Transpose int Trans, Double2 alpha, Allocation A, Double2 beta, Allocation C) {
Tim Murray25207df2015-01-12 16:47:56 -08001203 validateTranspose(Trans);
1204 validateUplo(Uplo);
1205 validateL3(Element.F64_2(mRS), Trans, 0, 0, A, null, C);
1206 int K = -1;
1207 if (Trans == TRANSPOSE) {
1208 K = A.getType().getY();
1209 } else {
1210 K = A.getType().getX();
1211 }
Miao Wang333bcc02015-04-22 15:57:57 -07001212 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zsyrk, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), K, alpha.x, alpha.y, A.getID(mRS), 0, beta.x, beta.y,
Tim Murray25207df2015-01-12 16:47:56 -08001213 C.getID(mRS), 0, 0, 0, 0);
1214 }
1215
1216 static void validateSYR2K(Element e, @Transpose int Trans, Allocation A, Allocation B, Allocation C) {
1217 validateTranspose(Trans);
1218 if (!A.getType().getElement().isCompatible(e) ||
1219 !B.getType().getElement().isCompatible(e) ||
1220 !C.getType().getElement().isCompatible(e)) {
1221 throw new RSRuntimeException("Called BLAS with wrong Element type");
1222 }
1223 int Cdim = -1;
1224 // A is n x k if no transpose, k x n if transpose
1225 // C is n x n
1226 if (Trans == TRANSPOSE) {
1227 // check columns versus C
1228 Cdim = A.getType().getX();
1229 } else {
1230 // check rows versus C
1231 Cdim = A.getType().getY();
1232 }
1233 if (C.getType().getX() != Cdim && C.getType().getY() != Cdim) {
1234 throw new RSRuntimeException("Invalid symmetric matrix in SYR2K");
1235 }
1236 // A dims == B dims
1237 if (A.getType().getX() != B.getType().getX() || A.getType().getY() != B.getType().getY()) {
1238 throw new RSRuntimeException("Invalid A and B in SYR2K");
1239 }
1240 }
1241 public void SSYR2K(@Uplo int Uplo, @Transpose int Trans, float alpha, Allocation A, Allocation B, float beta, Allocation C) {
1242 validateUplo(Uplo);
1243 validateSYR2K(Element.F32(mRS), Trans, A, B, C);
1244 int K = -1;
1245 if (Trans == TRANSPOSE) {
1246 K = A.getType().getY();
1247 } else {
1248 K = A.getType().getX();
1249 }
1250 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_ssyr2k, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), K, alpha, A.getID(mRS), B.getID(mRS), beta, C.getID(mRS), 0, 0, 0, 0);
1251 }
1252 public void DSYR2K(@Uplo int Uplo, @Transpose int Trans, double alpha, Allocation A, Allocation B, double beta, Allocation C) {
1253 validateUplo(Uplo);
1254 validateSYR2K(Element.F64(mRS), Trans, A, B, C);
1255 int K = -1;
1256 if (Trans == TRANSPOSE) {
1257 K = A.getType().getY();
1258 } else {
1259 K = A.getType().getX();
1260 }
1261 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_ssyr2k, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), K, alpha, A.getID(mRS), B.getID(mRS), beta, C.getID(mRS), 0, 0, 0, 0);
1262 }
1263 public void CSYR2K(@Uplo int Uplo, @Transpose int Trans, Float2 alpha, Allocation A, Allocation B, Float2 beta, Allocation C) {
1264 validateUplo(Uplo);
1265 validateSYR2K(Element.F32_2(mRS), Trans, A, B, C);
1266 int K = -1;
1267 if (Trans == TRANSPOSE) {
1268 K = A.getType().getY();
1269 } else {
1270 K = A.getType().getX();
1271 }
1272 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_ssyr2k, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), K, alpha.x, alpha.y, A.getID(mRS), B.getID(mRS), beta.x, beta.y, C.getID(mRS), 0, 0, 0, 0);
1273 }
1274 public void ZSYR2K(@Uplo int Uplo, @Transpose int Trans, Double2 alpha, Allocation A, Allocation B, Double2 beta, Allocation C) {
1275 validateUplo(Uplo);
1276 validateSYR2K(Element.F64_2(mRS), Trans, A, B, C);
1277 int K = -1;
1278 if (Trans == TRANSPOSE) {
1279 K = A.getType().getY();
1280 } else {
1281 K = A.getType().getX();
1282 }
1283 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_ssyr2k, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), K, alpha.x, alpha.y, A.getID(mRS), B.getID(mRS), beta.x, beta.y, C.getID(mRS), 0, 0, 0, 0);
1284 }
1285
1286 static void validateTRMM(Element e, @Side int Side, @Transpose int TransA, Allocation A, Allocation B) {
1287 validateSide(Side);
1288 validateTranspose(TransA);
1289 int aX = -1, aY = -1, bX = -1, bY = -1;
1290 if (!A.getType().getElement().isCompatible(e) ||
1291 !B.getType().getElement().isCompatible(e)) {
1292 throw new RSRuntimeException("Called BLAS with wrong Element type");
1293 }
1294 if (TransA == TRANSPOSE) {
1295 aY = A.getType().getY();
1296 aX = A.getType().getX();
1297 } else {
1298 aY = A.getType().getX();
1299 aX = A.getType().getY();
1300 }
1301 bX = B.getType().getY();
1302 bY = B.getType().getX();
1303 if (Side == LEFT) {
1304 if (aX == 0 || aY != bX) {
1305 throw new RSRuntimeException("Called TRMM with invalid matrices");
1306 }
1307 } else {
1308 if (bY != aX || aY == 0) {
1309 throw new RSRuntimeException("Called TRMM with invalid matrices");
1310 }
1311 }
1312 }
1313 public void STRMM(@Side int Side, @Uplo int Uplo, @Transpose int TransA, @Diag int Diag, float alpha, Allocation A, Allocation B) {
1314 validateUplo(Uplo);
1315 validateDiag(Diag);
1316 validateTRMM(Element.F32(mRS), Side, TransA, A, B);
1317 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_strmm, TransA, 0, Side, Uplo, Diag, B.getType().getY(), B.getType().getX(), 0,
1318 alpha, A.getID(mRS), B.getID(mRS), 0.f, 0, 0, 0, 0, 0);
1319 }
1320 public void DTRMM(@Side int Side, @Uplo int Uplo, @Transpose int TransA, @Diag int Diag, double alpha, Allocation A, Allocation B) {
1321 validateUplo(Uplo);
1322 validateDiag(Diag);
1323 validateTRMM(Element.F64(mRS), Side, TransA, A, B);
1324 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_strmm, TransA, 0, Side, Uplo, Diag, B.getType().getY(), B.getType().getX(), 0,
1325 alpha, A.getID(mRS), B.getID(mRS), 0.f, 0, 0, 0, 0, 0);
1326 }
1327 public void CTRMM(@Side int Side, @Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Float2 alpha, Allocation A, Allocation B) {
1328 validateUplo(Uplo);
1329 validateDiag(Diag);
1330 validateTRMM(Element.F32_2(mRS), Side, TransA, A, B);
1331 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_strmm, TransA, 0, Side, Uplo, Diag, B.getType().getY(), B.getType().getX(), 0,
1332 alpha.x, alpha.y, A.getID(mRS), B.getID(mRS), 0, 0, 0, 0, 0, 0, 0);
1333 }
1334 public void ZTRMM(@Side int Side, @Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Double2 alpha, Allocation A, Allocation B) {
1335 validateUplo(Uplo);
1336 validateDiag(Diag);
1337 validateTRMM(Element.F64_2(mRS), Side, TransA, A, B);
1338 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_strmm, TransA, 0, Side, Uplo, Diag, B.getType().getY(), B.getType().getX(), 0,
1339 alpha.x, alpha.y, A.getID(mRS), B.getID(mRS), 0, 0, 0, 0, 0, 0, 0);
1340 }
1341
1342 static void validateTRSM(Element e, @Side int Side, @Transpose int TransA, Allocation A, Allocation B) {
1343 int adim = -1, bX = -1, bY = -1;
1344 validateSide(Side);
1345 validateTranspose(TransA);
1346 if (!A.getType().getElement().isCompatible(e) ||
1347 !B.getType().getElement().isCompatible(e)) {
1348 throw new RSRuntimeException("Called BLAS with wrong Element type");
1349 }
1350 adim = A.getType().getX();
1351 if (adim != A.getType().getY()) {
1352 // this may be unnecessary, the restriction could potentially be relaxed
1353 // A needs to contain at least that symmetric matrix but could theoretically be larger
1354 // for now we assume adapters are sufficient, will reevaluate in the future
1355 throw new RSRuntimeException("Called TRSM with a non-symmetric matrix A");
1356 }
1357 bX = B.getType().getY();
1358 bY = B.getType().getX();
1359 if (Side == LEFT) {
1360 // A is M*M
1361 if (adim != bY) {
1362 throw new RSRuntimeException("Called TRSM with invalid matrix dimensions");
1363 }
1364 } else {
1365 // A is N*N
1366 if (adim != bX) {
1367 throw new RSRuntimeException("Called TRSM with invalid matrix dimensions");
1368 }
1369 }
1370 }
1371 public void STRSM(@Side int Side, @Uplo int Uplo, @Transpose int TransA, @Diag int Diag, float alpha, Allocation A, Allocation B) {
1372 validateUplo(Uplo);
1373 validateDiag(Diag);
1374 validateTRSM(Element.F32(mRS), Side, TransA, A, B);
1375 mRS.nScriptIntrinsicBLAS_Single(getID(mRS), RsBlas_strsm, TransA, 0, Side, Uplo, Diag, B.getType().getY(), B.getType().getX(), 0,
1376 alpha, A.getID(mRS), B.getID(mRS), 0, 0, 0, 0, 0, 0);
1377 }
1378 public void DTRSM(@Side int Side, @Uplo int Uplo, @Transpose int TransA, @Diag int Diag, double alpha, Allocation A, Allocation B) {
1379 validateUplo(Uplo);
1380 validateDiag(Diag);
1381 validateTRSM(Element.F64(mRS), Side, TransA, A, B);
1382 mRS.nScriptIntrinsicBLAS_Double(getID(mRS), RsBlas_strsm, TransA, 0, Side, Uplo, Diag, B.getType().getY(), B.getType().getX(), 0,
1383 alpha, A.getID(mRS), B.getID(mRS), 0, 0, 0, 0, 0, 0);
1384 }
1385 public void CTRSM(@Side int Side, @Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Float2 alpha, Allocation A, Allocation B) {
1386 validateUplo(Uplo);
1387 validateDiag(Diag);
1388 validateTRSM(Element.F32_2(mRS), Side, TransA, A, B);
1389 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_strsm, TransA, 0, Side, Uplo, Diag, B.getType().getY(), B.getType().getX(), 0,
1390 alpha.x, alpha.y, A.getID(mRS), B.getID(mRS), 0, 0, 0, 0, 0, 0, 0);
1391 }
1392 public void ZTRSM(@Side int Side, @Uplo int Uplo, @Transpose int TransA, @Diag int Diag, Double2 alpha, Allocation A, Allocation B) {
1393 validateUplo(Uplo);
1394 validateDiag(Diag);
1395 validateTRSM(Element.F64_2(mRS), Side, TransA, A, B);
1396 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_strsm, TransA, 0, Side, Uplo, Diag, B.getType().getY(), B.getType().getX(), 0,
1397 alpha.x, alpha.y, A.getID(mRS), B.getID(mRS), 0, 0, 0, 0, 0, 0, 0);
1398 }
1399
1400 static void validateHEMM(Element e, @Side int Side, Allocation A, Allocation B, Allocation C) {
1401 validateSide(Side);
1402
1403 if (!A.getType().getElement().isCompatible(e) ||
1404 !B.getType().getElement().isCompatible(e) ||
1405 !C.getType().getElement().isCompatible(e)) {
1406 throw new RSRuntimeException("Called BLAS with wrong Element type");
1407 }
1408
1409 // A must be square; can potentially be relaxed similar to TRSM
1410 int adim = A.getType().getX();
1411 if (adim != A.getType().getY()) {
1412 throw new RSRuntimeException("Called HEMM with non-square A");
1413 }
1414 if ((Side == LEFT && adim != B.getType().getY()) ||
1415 (Side == RIGHT && adim != B.getType().getX())) {
1416 throw new RSRuntimeException("Called HEMM with invalid B");
1417 }
1418 if (B.getType().getX() != C.getType().getX() ||
1419 B.getType().getY() != C.getType().getY()) {
1420 throw new RSRuntimeException("Called HEMM with mismatched B and C");
1421 }
1422 }
Miao Wang333bcc02015-04-22 15:57:57 -07001423 public void CHEMM(@Side int Side, @Uplo int Uplo, Float2 alpha, Allocation A, Allocation B, Float2 beta, Allocation C) {
Tim Murray25207df2015-01-12 16:47:56 -08001424 validateUplo(Uplo);
1425 validateHEMM(Element.F32_2(mRS), Side, A, B, C);
1426 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_chemm, 0, 0, Side, Uplo, 0, C.getType().getY(), C.getType().getX(), 0,
Miao Wang333bcc02015-04-22 15:57:57 -07001427 alpha.x, alpha.y, A.getID(mRS), B.getID(mRS), beta.x, beta.y, C.getID(mRS), 0, 0, 0, 0);
Tim Murray25207df2015-01-12 16:47:56 -08001428 }
Miao Wang333bcc02015-04-22 15:57:57 -07001429 public void ZHEMM(@Side int Side, @Uplo int Uplo, Double2 alpha, Allocation A, Allocation B, Double2 beta, Allocation C) {
Tim Murray25207df2015-01-12 16:47:56 -08001430 validateUplo(Uplo);
1431 validateHEMM(Element.F32_2(mRS), Side, A, B, C);
1432 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zhemm, 0, 0, Side, Uplo, 0, C.getType().getY(), C.getType().getX(), 0,
Miao Wang333bcc02015-04-22 15:57:57 -07001433 alpha.x, alpha.y, A.getID(mRS), B.getID(mRS), beta.x, beta.y, C.getID(mRS), 0, 0, 0, 0);
Tim Murray25207df2015-01-12 16:47:56 -08001434 }
1435
1436 static void validateHERK(Element e, @Transpose int Trans, Allocation A, Allocation C) {
1437 if (!A.getType().getElement().isCompatible(e) ||
1438 !C.getType().getElement().isCompatible(e)) {
1439 throw new RSRuntimeException("Called BLAS with wrong Element type");
1440 }
1441 validateConjTranspose(Trans);
1442 int cdim = C.getType().getX();
1443 if (cdim != C.getType().getY()) {
1444 throw new RSRuntimeException("Called HERK with non-square C");
1445 }
1446 if (Trans == NO_TRANSPOSE) {
1447 if (cdim != A.getType().getX()) {
1448 throw new RSRuntimeException("Called HERK with invalid A");
1449 }
1450 } else {
1451 if (cdim != A.getType().getY()) {
1452 throw new RSRuntimeException("Called HERK with invalid A");
1453 }
1454 }
1455 }
1456 public void CHERK(@Uplo int Uplo, @Transpose int Trans, float alpha, Allocation A, float beta, Allocation C) {
1457 validateUplo(Uplo);
1458 validateHERK(Element.F32_2(mRS), Trans, A, C);
1459 int k = 0;
1460 if (Trans == TRANSPOSE) {
1461 k = A.getType().getY();
1462 } else {
1463 k = A.getType().getX();
1464 }
1465 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_cherk, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), k,
1466 alpha, 0, A.getID(mRS), 0, beta, 0, C.getID(mRS), 0, 0, 0, 0);
1467 }
1468 public void ZHERK(@Uplo int Uplo, @Transpose int Trans, double alpha, Allocation A, double beta, Allocation C) {
1469 validateUplo(Uplo);
1470 validateHERK(Element.F64_2(mRS), Trans, A, C);
1471 int k = 0;
1472 if (Trans == TRANSPOSE) {
1473 k = A.getType().getY();
1474 } else {
1475 k = A.getType().getX();
1476 }
1477 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zherk, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), k,
1478 alpha, 0, A.getID(mRS), 0, beta, 0, C.getID(mRS), 0, 0, 0, 0);
1479 }
1480
1481 static void validateHER2K(Element e, @Transpose int Trans, Allocation A, Allocation B, Allocation C) {
1482 if (!A.getType().getElement().isCompatible(e) ||
1483 !B.getType().getElement().isCompatible(e) ||
1484 !C.getType().getElement().isCompatible(e)) {
1485 throw new RSRuntimeException("Called BLAS with wrong Element type");
1486 }
1487 validateConjTranspose(Trans);
1488 int cdim = C.getType().getX();
1489 if (cdim != C.getType().getY()) {
1490 throw new RSRuntimeException("Called HER2K with non-square C");
1491 }
1492 if (Trans == NO_TRANSPOSE) {
1493 if (A.getType().getY() != cdim) {
1494 throw new RSRuntimeException("Called HER2K with invalid matrices");
1495 }
1496 } else {
1497 if (A.getType().getX() != cdim) {
1498 throw new RSRuntimeException("Called HER2K with invalid matrices");
1499 }
1500 }
1501 if (A.getType().getX() != B.getType().getX() || A.getType().getY() != B.getType().getY()) {
1502 throw new RSRuntimeException("Called HER2K with invalid A and B matrices");
1503 }
1504 }
1505 public void CHER2K(@Uplo int Uplo, @Transpose int Trans, Float2 alpha, Allocation A, Allocation B, float beta, Allocation C) {
1506 validateUplo(Uplo);
1507 validateHER2K(Element.F32_2(mRS), Trans, A, B, C);
1508 int k = 0;
1509 if (Trans == NO_TRANSPOSE) {
1510 k = A.getType().getX();
1511 } else {
1512 k = A.getType().getY();
1513 }
1514 mRS.nScriptIntrinsicBLAS_Complex(getID(mRS), RsBlas_cher2k, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), k, alpha.x, alpha.y,
1515 A.getID(mRS), B.getID(mRS), beta, 0, C.getID(mRS), 0, 0, 0, 0);
1516 }
1517 public void ZHER2K(@Uplo int Uplo, @Transpose int Trans, Double2 alpha, Allocation A, Allocation B, double beta, Allocation C) {
1518 validateUplo(Uplo);
1519 validateHER2K(Element.F64_2(mRS), Trans, A, B, C);
1520 int k = 0;
1521 if (Trans == NO_TRANSPOSE) {
1522 k = A.getType().getX();
1523 } else {
1524 k = A.getType().getY();
1525 }
1526 mRS.nScriptIntrinsicBLAS_Z(getID(mRS), RsBlas_zher2k, Trans, 0, 0, Uplo, 0, 0, C.getType().getX(), k, alpha.x, alpha.y,
1527 A.getID(mRS), B.getID(mRS), beta, 0, C.getID(mRS), 0, 0, 0, 0);
1528 }
1529
1530
Tim Murray9cb16a22015-04-01 11:07:16 -07001531 /**
1532 *
1533 * 8-bit GEMM-like operation for neural networks
1534 *
1535 * @hide
1536 **/
1537 public void BNNM(Allocation A, int a_offset, Allocation B, int b_offset, Allocation C, int c_offset, int c_mult) {
1538 validateL3(Element.U8(mRS), NO_TRANSPOSE, TRANSPOSE, 0, A, B, C);
1539
1540 int M = -1, N = -1, K = -1;
1541 M = A.getType().getY();
1542 N = B.getType().getY();
1543 K = A.getType().getX();
1544
1545
1546 mRS.nScriptIntrinsicBLAS_BNNM(getID(mRS), M, N, K, A.getID(mRS), a_offset, B.getID(mRS), b_offset, C.getID(mRS), c_offset, c_mult);
1547
1548 }
Tim Murray25207df2015-01-12 16:47:56 -08001549
1550}