jcuda.jcublas.JCublas2 Java Examples
The following examples show how to use
jcuda.jcublas.JCublas2.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CublasUtil.java From murphy with Apache License 2.0 | 5 votes |
public float[] toArray() { float[] data_h = new float[rows*cols]; // JCublas2.cublasGetVector(data_h.length, Sizeof.FLOAT, data_d, 1, Pointer.to(data_h), 1); JCublas2.cublasGetMatrix(rows, cols, Sizeof.FLOAT, data_d, rows, Pointer.to(data_h), rows); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); return data_h; }
Example #2
Source File: CublasUtil.java From murphy with Apache License 2.0 | 5 votes |
public Matrix copy() { Matrix result = new Matrix(rows, cols); JCublas2.cublasScopy(cublasHandle, this.rows*this.cols, this.data_d, 1, result.data_d, 1); // JCublas2.cublasSetMatrix(result.rows, result.cols, Sizeof.FLOAT, this.data_d, result.rows, result.data_d, result.rows); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); return result; }
Example #3
Source File: CublasUtil.java From murphy with Apache License 2.0 | 5 votes |
public static Matrix build(float[][] mat) { Matrix result = new Matrix(mat.length, mat[0].length); float[] data_h = toColMajor(mat); JCublas2.cublasSetMatrix(result.rows, result.cols, Sizeof.FLOAT, Pointer.to(data_h), result.rows, result.data_d, result.rows); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); return result; }
Example #4
Source File: CublasUtil.java From murphy with Apache License 2.0 | 5 votes |
private static void getrfGetriBatched(List<Matrix> A, List<Matrix> B) { Pointer[] Apointers = new Pointer[A.size()]; Pointer[] Bpointers = new Pointer[B.size()]; for (int i=0; i<A.size(); ++i) { Apointers[i] = A.get(i).data_d; Bpointers[i] = B.get(i).data_d; } Pointer Apointers_d = new Pointer(); JCuda.cudaMalloc(Apointers_d, A.size() * Sizeof.POINTER); JCuda.cudaMemcpy(Apointers_d, Pointer.to(Apointers), A.size() * Sizeof.POINTER, cudaMemcpyKind.cudaMemcpyHostToDevice); Pointer Bpointers_d = new Pointer(); JCuda.cudaMalloc(Bpointers_d, B.size() * Sizeof.POINTER); JCuda.cudaMemcpy(Bpointers_d, Pointer.to(Bpointers), B.size() * Sizeof.POINTER, cudaMemcpyKind.cudaMemcpyHostToDevice); Pointer info_d = new Pointer(); JCuda.cudaMalloc(info_d, A.size() * Sizeof.INT); Pointer pivots_d = new Pointer(); JCuda.cudaMalloc(pivots_d, A.get(0).rows * A.size() * Sizeof.INT); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); JCublas2.cublasSgetrfBatched(cublasHandle, A.get(0).rows, Apointers_d, A.get(0).rows, pivots_d, info_d, A.size()); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); JCublas2.cublasSgetriBatched(cublasHandle, A.get(0).rows, Apointers_d, A.get(0).rows, pivots_d, Bpointers_d, B.get(0).rows, info_d, A.size()); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); JCuda.cudaFree(Apointers_d); JCuda.cudaFree(Bpointers_d); JCuda.cudaFree(info_d); JCuda.cudaFree(pivots_d); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); }
Example #5
Source File: CublasUtil.java From murphy with Apache License 2.0 | 5 votes |
public static void startup(int deviceId) { CudaUtil.startup(deviceId); cublasHandle = new cublasHandle(); JCublas2.cublasCreate(cublasHandle); helperModule = CudaUtil.compileAndLoad("la_helper_funs", Matrix.kernels, true); allocated = new LinkedList<Matrix>(); JCublas2.cublasSetAtomicsMode(cublasHandle, cublasAtomicsMode.CUBLAS_ATOMICS_ALLOWED); JCublas2.cublasSetPointerMode(cublasHandle, cublasPointerMode.CUBLAS_POINTER_MODE_HOST); }
Example #6
Source File: JCudnnMnist.java From jcuda-samples with MIT License | 5 votes |
public static void main(String args[]) { JCuda.setExceptionsEnabled(true); JCudnn.setExceptionsEnabled(true); JCublas2.setExceptionsEnabled(true); int version = (int) cudnnGetVersion(); System.out.printf("cudnnGetVersion() : %d , " + "CUDNN_VERSION from cudnn.h : %d\n", version, CUDNN_VERSION); System.out.println("Creating network and layers..."); Network mnist = new Network(); System.out.println("Classifying..."); int i1 = mnist.classifyExample(dataDirectory + first_image); int i2 = mnist.classifyExample(dataDirectory + second_image); mnist.setConvolutionAlgorithm(CUDNN_CONVOLUTION_FWD_ALGO_FFT); int i3 = mnist.classifyExample(dataDirectory + third_image); System.out.println( "\nResult of classification: " + i1 + " " + i2 + " " + i3); if (i1 != 1 || i2 != 3 || i3 != 5) { System.out.println("\nTest failed!\n"); } else { System.out.println("\nTest passed!\n"); } mnist.destroy(); }
Example #7
Source File: CublasUtil.java From murphy with Apache License 2.0 | 5 votes |
private static void gemmBatched(float alpha, List<Matrix> A, List<Matrix> B, float beta, List<Matrix> C) { Pointer[] Apointers = new Pointer[A.size()]; Pointer[] Bpointers = new Pointer[B.size()]; Pointer[] Cpointers = new Pointer[C.size()]; for (int i=0; i<A.size(); ++i) { Apointers[i] = A.get(i).data_d; Bpointers[i] = B.get(i).data_d; Cpointers[i] = C.get(i).data_d; } Pointer Apointers_d = new Pointer(); JCuda.cudaMalloc(Apointers_d, A.size() * Sizeof.POINTER); JCuda.cudaMemcpy(Apointers_d, Pointer.to(Apointers), A.size() * Sizeof.POINTER, cudaMemcpyKind.cudaMemcpyHostToDevice); Pointer Bpointers_d = new Pointer(); JCuda.cudaMalloc(Bpointers_d, B.size() * Sizeof.POINTER); JCuda.cudaMemcpy(Bpointers_d, Pointer.to(Bpointers), B.size() * Sizeof.POINTER, cudaMemcpyKind.cudaMemcpyHostToDevice); Pointer Cpointers_d = new Pointer(); JCuda.cudaMalloc(Cpointers_d, C.size() * Sizeof.POINTER); JCuda.cudaMemcpy(Cpointers_d, Pointer.to(Cpointers), C.size() * Sizeof.POINTER, cudaMemcpyKind.cudaMemcpyHostToDevice); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); JCublas2.cublasSgemmBatched(cublasHandle, cublasOperation.CUBLAS_OP_N, cublasOperation.CUBLAS_OP_N, C.get(0).rows, C.get(0).cols, B.get(0).rows, Pointer.to(new float[] {alpha}), Apointers_d, A.get(0).rows, Bpointers_d, B.get(0).rows, Pointer.to(new float[] {beta}), Cpointers_d, C.get(0).rows, A.size()); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); JCuda.cudaFree(Apointers_d); JCuda.cudaFree(Bpointers_d); JCuda.cudaFree(Cpointers_d); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); }
Example #8
Source File: CublasUtil.java From murphy with Apache License 2.0 | 4 votes |
private static void ger(float alpha, Matrix x, Matrix y, Matrix A) { JCublas2.cublasSger(cublasHandle, A.rows, A.cols, Pointer.to(new float[] {alpha}), x.data_d, 1, y.data_d, 1, A.data_d, A.rows); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); }
Example #9
Source File: CublasUtil.java From murphy with Apache License 2.0 | 4 votes |
public Matrix comb(float alpha, float beta, Matrix that) { Matrix result = new Matrix(rows, cols); JCublas2.cublasSgeam(cublasHandle, cublasOperation.CUBLAS_OP_N, cublasOperation.CUBLAS_OP_N, rows, cols, Pointer.to(new float[] {alpha}), data_d, rows, Pointer.to(new float[] {beta}), that.data_d, that.rows, result.data_d, result.rows); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); return result; }
Example #10
Source File: CublasUtil.java From murphy with Apache License 2.0 | 4 votes |
public Matrix muli(float alpha) { JCublas2.cublasSscal(cublasHandle, rows*cols, Pointer.to(new float[] {alpha}), data_d, 1); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); return this; }
Example #11
Source File: CublasUtil.java From murphy with Apache License 2.0 | 4 votes |
public Matrix transpose() { Matrix result = new Matrix(cols, rows); JCublas2.cublasSgeam(cublasHandle, cublasOperation.CUBLAS_OP_T, cublasOperation.CUBLAS_OP_T, cols, rows, Pointer.to(new float[] {1.0f}), data_d, rows, Pointer.to(new float[] {0.0f}), new Pointer(), rows, result.data_d, result.rows); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); return result; }
Example #12
Source File: CublasUtil.java From murphy with Apache License 2.0 | 4 votes |
public Matrix zeroi() { JCublas2.cublasSgeam(cublasHandle, cublasOperation.CUBLAS_OP_N, cublasOperation.CUBLAS_OP_N, rows, cols, Pointer.to(new float[] {0.0f}), new Pointer(), rows, Pointer.to(new float[] {0.0f}), new Pointer(), rows, data_d, rows); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); return this; }
Example #13
Source File: CublasUtil.java From murphy with Apache License 2.0 | 4 votes |
public float norm1() { float[] result = new float[1]; JCublas2.cublasSasum(cublasHandle, rows*cols, data_d, 1, Pointer.to(result)); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); return result[0]; }
Example #14
Source File: CublasUtil.java From murphy with Apache License 2.0 | 4 votes |
public float norm2() { float[] result = new float[1]; JCublas2.cublasSnrm2(cublasHandle, rows*cols, data_d, 1, Pointer.to(result)); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); return result[0]; }
Example #15
Source File: CublasUtil.java From murphy with Apache License 2.0 | 4 votes |
private static void gemm(float alpha, Matrix A, Matrix B, float beta, Matrix C) { JCublas2.cublasSgemm(cublasHandle, cublasOperation.CUBLAS_OP_N, cublasOperation.CUBLAS_OP_N, C.rows, C.cols, B.rows, Pointer.to(new float[] {alpha}), A.data_d, A.rows, B.data_d, B.rows, Pointer.to(new float[] {beta}), C.data_d, C.rows); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); }
Example #16
Source File: CublasUtil.java From murphy with Apache License 2.0 | 4 votes |
private static void dgmm(Matrix A, Matrix x, Matrix B, boolean left) { JCublas2.cublasSdgmm(cublasHandle, left ? cublasSideMode.CUBLAS_SIDE_LEFT : cublasSideMode.CUBLAS_SIDE_RIGHT, A.rows, A.cols, A.data_d, A.rows, x.data_d, 1, B.data_d, B.rows); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); }
Example #17
Source File: CublasUtil.java From murphy with Apache License 2.0 | 4 votes |
public Matrix setSubmatrix(float[][] mat, int r, int c) { float[] data_h = toColMajor(mat); JCublas2.cublasSetMatrix(mat.length, mat[0].length, Sizeof.FLOAT, Pointer.to(data_h), mat.length, this.data_d.withByteOffset((c*this.rows+r)*Sizeof.FLOAT), this.rows); if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize(); return this; }
Example #18
Source File: DoublePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublasgeam(cublasHandle handle, int transa, int transb, int m, int n, Pointer alpha, Pointer A, int lda, Pointer beta, Pointer B, int ldb, Pointer C, int ldc) { return JCublas2.cublasDgeam(handle, transa, transb, m, n, alpha, A, lda, beta, B, ldb, C, ldc); }
Example #19
Source File: DoublePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublasdot(cublasHandle handle, int n, Pointer x, int incx, Pointer y, int incy, Pointer result) { return JCublas2.cublasDdot(handle, n, x, incx, y, incy, result); }
Example #20
Source File: DoublePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublasgemv(cublasHandle handle, int trans, int m, int n, Pointer alpha, Pointer A, int lda, Pointer x, int incx, Pointer beta, Pointer y, int incy) { return JCublas2.cublasDgemv(handle, trans, m, n, alpha, A, lda, x, incx, beta, y, incy); }
Example #21
Source File: DoublePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublasgemm(cublasHandle handle, int transa, int transb, int m, int n, int k, Pointer alpha, Pointer A, int lda, Pointer B, int ldb, Pointer beta, Pointer C, int ldc) { return JCublas2.cublasDgemm(handle, transa, transb, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc); }
Example #22
Source File: DoublePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublassyrk(cublasHandle handle, int uplo, int trans, int n, int k, Pointer alpha, Pointer A, int lda, Pointer beta, Pointer C, int ldc) { return JCublas2.cublasDsyrk(handle, uplo, trans, n, k, alpha, A, lda, beta, C, ldc); }
Example #23
Source File: DoublePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublasaxpy(cublasHandle handle, int n, Pointer alpha, Pointer x, int incx, Pointer y, int incy) { return JCublas2.cublasDaxpy(handle, n, alpha, x, incx, y, incy); }
Example #24
Source File: DoublePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublastrsm(cublasHandle handle, int side, int uplo, int trans, int diag, int m, int n, Pointer alpha, Pointer A, int lda, Pointer B, int ldb) { return JCublas2.cublasDtrsm(handle, side, uplo, trans, diag, m, n, alpha, A, lda, B, ldb); }
Example #25
Source File: SinglePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublasgeam(cublasHandle handle, int transa, int transb, int m, int n, Pointer alpha, Pointer A, int lda, Pointer beta, Pointer B, int ldb, Pointer C, int ldc) { return JCublas2.cublasSgeam(handle, transa, transb, m, n, alpha, A, lda, beta, B, ldb, C, ldc); }
Example #26
Source File: SinglePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublasdot(cublasHandle handle, int n, Pointer x, int incx, Pointer y, int incy, Pointer result) { return JCublas2.cublasSdot(handle, n, x, incx, y, incy, result); }
Example #27
Source File: SinglePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublasgemv(cublasHandle handle, int trans, int m, int n, Pointer alpha, Pointer A, int lda, Pointer x, int incx, Pointer beta, Pointer y, int incy) { return JCublas2.cublasSgemv(handle, trans, m, n, alpha, A, lda, x, incx, beta, y, incy); }
Example #28
Source File: SinglePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublasgemm(cublasHandle handle, int transa, int transb, int m, int n, int k, Pointer alpha, Pointer A, int lda, Pointer B, int ldb, Pointer beta, Pointer C, int ldc) { return JCublas2.cublasSgemm(handle, transa, transb, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc); }
Example #29
Source File: SinglePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublassyrk(cublasHandle handle, int uplo, int trans, int n, int k, Pointer alpha, Pointer A, int lda, Pointer beta, Pointer C, int ldc) { return JCublas2.cublasSsyrk(handle, uplo, trans, n, k, alpha, A, lda, beta, C, ldc); }
Example #30
Source File: SinglePrecisionCudaSupportFunctions.java From systemds with Apache License 2.0 | 4 votes |
@Override public int cublasaxpy(cublasHandle handle, int n, Pointer alpha, Pointer x, int incx, Pointer y, int incy) { return JCublas2.cublasSaxpy(handle, n, alpha, x, incx, y, incy); }