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