org.bytedeco.javacpp.FloatPointer Java Examples
The following examples show how to use
org.bytedeco.javacpp.FloatPointer.
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: JcublasLevel3.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override protected void ssyrk(char Order, char Uplo, char Trans, int N, int K, float alpha, INDArray A, int lda, float beta, INDArray C, int ldc) { Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(C, A); CublasPointer aPointer = new CublasPointer(A, ctx); CublasPointer cPointer = new CublasPointer(C, ctx); cublasHandle_t handle = ctx.getCublasHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getCublasStream())); cublasSsyrk_v2(new cublasContext(handle), convertUplo(Uplo), convertTranspose(Trans), N, K, new FloatPointer(alpha), (FloatPointer) aPointer.getDevicePointer(), lda, new FloatPointer(beta), (FloatPointer) cPointer.getDevicePointer(), ldc); } allocator.registerAction(ctx, C, A); OpExecutionerUtil.checkForAny(C); }
Example #2
Source File: JcublasLevel3.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected void strsm(char Order, char Side, char Uplo, char TransA, char Diag, int M, int N, float alpha, INDArray A, int lda, INDArray B, int ldb) { if (Nd4j.dataType() != DataBuffer.Type.FLOAT) logger.warn("FLOAT trsm called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(B, A); CublasPointer aPointer = new CublasPointer(A, ctx); CublasPointer bPointer = new CublasPointer(B, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); cublasStrsm_v2(new cublasContext(handle), convertSideMode(Side), convertUplo(Uplo), convertTranspose(TransA), convertDiag(Diag), M, N, new FloatPointer(alpha), (FloatPointer) aPointer.getDevicePointer(), lda, (FloatPointer) bPointer.getDevicePointer(), ldb); } allocator.registerAction(ctx, B, A); OpExecutionerUtil.checkForAny(B); }
Example #3
Source File: JcublasLevel1.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected void sswap(long N, INDArray X, int incX, INDArray Y, int incY) { if (Nd4j.dataType() != DataBuffer.Type.FLOAT) logger.warn("FLOAT swap called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(Y, X); CublasPointer xCPointer = new CublasPointer(X, ctx); CublasPointer yCPointer = new CublasPointer(Y, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); cublasSswap_v2(new cublasContext(handle), (int) N, (FloatPointer) xCPointer.getDevicePointer(), incX, (FloatPointer) yCPointer.getDevicePointer(), incY); } allocator.registerAction(ctx, Y, X); OpExecutionerUtil.checkForAny(Y); }
Example #4
Source File: JcublasLevel1.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected void scopy(long N, INDArray X, int incX, INDArray Y, int incY) { if (Nd4j.dataType() != DataBuffer.Type.FLOAT) logger.warn("FLOAT copy called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(Y, X); CublasPointer xCPointer = new CublasPointer(X, ctx); CublasPointer yCPointer = new CublasPointer(Y, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); cublasScopy_v2(new cublasContext(handle), (int) N, (FloatPointer) xCPointer.getDevicePointer(), incX, (FloatPointer) yCPointer.getDevicePointer(), incY); } allocator.registerAction(ctx, Y, X); OpExecutionerUtil.checkForAny(Y); }
Example #5
Source File: JcublasLevel1.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected void sscal(long N, float alpha, INDArray X, int incX) { if (Nd4j.dataType() != DataBuffer.Type.FLOAT) logger.warn("FLOAT scal called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(X); CublasPointer xCPointer = new CublasPointer(X, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); cublasSscal_v2(new cublasContext(handle),(int) N, new FloatPointer(alpha), (FloatPointer) xCPointer.getDevicePointer(), incX); } allocator.registerAction(ctx, X); OpExecutionerUtil.checkForAny(X); }
Example #6
Source File: CpuLevel2.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override protected void ssbmv(char order, char Uplo, int N, int K, float alpha, INDArray A, int lda, INDArray X, int incX, float beta, INDArray Y, int incY) { cblas_ssbmv(convertOrder('f'), convertUplo(Uplo), N, K, alpha, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) X.data().addressPointer(), incX, beta, (FloatPointer) Y.data().addressPointer(), incY); }
Example #7
Source File: CpuLapack.java From nd4j with Apache License 2.0 | 5 votes |
@Override public void sgesvd(byte jobu, byte jobvt, int M, int N, INDArray A, INDArray S, INDArray U, INDArray VT, INDArray INFO) { INDArray superb = Nd4j.create( M < N ? M : N ) ; int status = LAPACKE_sgesvd(getColumnOrder(A), jobu, jobvt, M, N, (FloatPointer)A.data().addressPointer(), getLda(A), (FloatPointer)S.data().addressPointer(), U == null ? null : (FloatPointer)U.data().addressPointer(), U == null ? 1 : getLda(U), VT == null ? null : (FloatPointer)VT.data().addressPointer(), VT == null ? 1 : getLda(VT), (FloatPointer)superb.data().addressPointer() ); if( status != 0 ) { throw new BlasException( "Failed to execute sgesvd", status ) ; } }
Example #8
Source File: CpuLevel3.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override protected void strmm(char Order, char Side, char Uplo, char TransA, char Diag, int M, int N, float alpha, INDArray A, int lda, INDArray B, int ldb) { cblas_strmm(convertOrder('f'), convertSide(Side), convertUplo(Uplo), convertTranspose(TransA), Diag, M, N, alpha, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) B.data().addressPointer(), ldb); }
Example #9
Source File: OnnxTest.java From konduit-serving with Apache License 2.0 | 5 votes |
@Test public void runSqueezenet(TestContext testContext) throws Exception { long inputTensorSize = 224 * 224 * 3; FloatPointer inputTensorValues = new FloatPointer(inputTensorSize); FloatIndexer idx = FloatIndexer.create(inputTensorValues); for (long i = 0; i < inputTensorSize; i++) idx.put(i, (float) i / (inputTensorSize + 1)); DataBuffer buffer = Nd4j.createBuffer(inputTensorValues, DataType.FLOAT, inputTensorSize, idx); INDArray contents = Nd4j.create(buffer); byte[] npyContents = Nd4j.toNpyByteArray(contents); File inputFile = temporary.newFile(); FileUtils.writeByteArrayToFile(inputFile, npyContents); for (int i = 0; i < 5; i++) { Response response = given().port(port) .multiPart("data_0", inputFile) .post("nd4j/numpy") .andReturn(); //TODO: report memory leak in DNNL execution provider to ORT assertEquals("Response failed", 200, response.getStatusCode()); INDArray bodyResult = Nd4j.createNpyFromByteArray(response.getBody().asByteArray()); assertEquals(1.99018, bodyResult.getFloat(0), 1e-4); assertArrayEquals(new long[]{1, 1000}, bodyResult.shape()); } }
Example #10
Source File: CpuLapack.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public void sgesvd(byte jobu, byte jobvt, int M, int N, INDArray A, INDArray S, INDArray U, INDArray VT, INDArray INFO) { INDArray superb = Nd4j.create(DataType.FLOAT, M < N ? M : N ) ; int status = LAPACKE_sgesvd(getColumnOrder(A), jobu, jobvt, M, N, (FloatPointer)A.data().addressPointer(), getLda(A), (FloatPointer)S.data().addressPointer(), U == null ? null : (FloatPointer)U.data().addressPointer(), U == null ? 1 : getLda(U), VT == null ? null : (FloatPointer)VT.data().addressPointer(), VT == null ? 1 : getLda(VT), (FloatPointer)superb.data().addressPointer() ); if( status != 0 ) { throw new BlasException( "Failed to execute sgesvd", status ) ; } }
Example #11
Source File: JcublasLevel3.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void sgemm(char Order, char TransA, char TransB, int M, int N, int K, float alpha, INDArray A, int lda, INDArray B, int ldb, float beta, INDArray C, int ldc) { //A = Shape.toOffsetZero(A); //B = Shape.toOffsetZero(B); if (Nd4j.dataType() != DataBuffer.Type.FLOAT) logger.warn("FLOAT gemm called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(C, A, B); CublasPointer cAPointer = new CublasPointer(A, ctx); CublasPointer cBPointer = new CublasPointer(B, ctx); CublasPointer cCPointer = new CublasPointer(C, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); cublasSgemm_v2(new cublasContext(handle), convertTranspose(TransA), convertTranspose(TransB), M, N, K, new FloatPointer(alpha), (FloatPointer) cAPointer.getDevicePointer(), lda, (FloatPointer) cBPointer.getDevicePointer(), ldb, new FloatPointer(beta), (FloatPointer) cCPointer.getDevicePointer(), ldc); } allocator.registerAction(ctx, C, A, B); OpExecutionerUtil.checkForAny(C); }
Example #12
Source File: JcublasLevel3.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void ssymm(char Order, char Side, char Uplo, int M, int N, float alpha, INDArray A, int lda, INDArray B, int ldb, float beta, INDArray C, int ldc) { if (Nd4j.dataType() != DataBuffer.Type.FLOAT) logger.warn("FLOAT symm called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(C, A, B); CublasPointer aPointer = new CublasPointer(A, ctx); CublasPointer bPointer = new CublasPointer(B, ctx); CublasPointer cPointer = new CublasPointer(C, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); cublasSsymm_v2(new cublasContext(handle), convertSideMode(Side), convertUplo(Uplo), M, N, new FloatPointer(alpha), (FloatPointer) aPointer.getDevicePointer(), lda, (FloatPointer) bPointer.getDevicePointer(), ldb, new FloatPointer(beta), (FloatPointer) cPointer.getDevicePointer(), ldc); } allocator.registerAction(ctx, C, A, B); OpExecutionerUtil.checkForAny(C); }
Example #13
Source File: CpuLevel3.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override protected void ssyrk(char Order, char Uplo, char Trans, int N, int K, float alpha, INDArray A, int lda, float beta, INDArray C, int ldc) { cblas_ssyrk(convertOrder('f'), convertUplo(Uplo), convertTranspose(Trans), N, K, alpha, (FloatPointer) A.data().addressPointer(), lda, beta, (FloatPointer) C.data().addressPointer(), ldc); }
Example #14
Source File: JcublasLevel1.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected float sdot(long N, INDArray X, int incX, INDArray Y, int incY) { if (Nd4j.dataType() != DataBuffer.Type.FLOAT) logger.warn("FLOAT dot called"); DataTypeValidation.assertSameDataType(X, Y); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(null, X, Y); float ret = 1f; CublasPointer xCPointer = new CublasPointer(X, ctx); CublasPointer yCPointer = new CublasPointer(Y, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { long result = cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); if (result != 0) throw new IllegalStateException("cublasSetStream failed"); FloatPointer resultPointer = new FloatPointer(0.0f); result = cublasSdot_v2(new cublasContext(handle), (int) N, (FloatPointer) xCPointer.getDevicePointer(), incX, (FloatPointer) yCPointer.getDevicePointer(), incY, resultPointer); ret = resultPointer.get(); } allocator.registerAction(ctx, null, X, Y); return ret; }
Example #15
Source File: JcublasLevel1.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected float snrm2(long N, INDArray X, int incX) { if (Nd4j.dataType() != DataBuffer.Type.FLOAT) logger.warn("FLOAT nrm2 called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(null, X); float ret; CublasPointer cAPointer = new CublasPointer(X, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); FloatPointer resultPointer = new FloatPointer(0.0f); cublasSnrm2_v2(new cublasContext(handle), (int) N, (FloatPointer) cAPointer.getDevicePointer(), incX, resultPointer); ret = resultPointer.get(); } allocator.registerAction(ctx, null, X); return ret; }
Example #16
Source File: CpuLevel1.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected float sdot(long N, INDArray X, int incX, INDArray Y, int incY) { if (incX >= 1 && incY >= 1) { return cblas_sdot((int) N, (FloatPointer) X.data().addressPointer(), incX, (FloatPointer) Y.data().addressPointer(), incY); } else { // non-EWS dot variant Dot dot = new Dot(X, Y); Nd4j.getExecutioner().exec(dot); return dot.getFinalResult().floatValue(); } }
Example #17
Source File: CpuLevel2.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override protected void stbsv(char order, char Uplo, char TransA, char Diag, int N, int K, INDArray A, int lda, INDArray X, int incX) { cblas_stbsv(convertOrder('f'), convertUplo(Uplo), convertTranspose(TransA), convertDiag(Diag), N, K, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) X.data().addressPointer(), incX); }
Example #18
Source File: SparseCpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
public void scoomv(char transA, int M, DataBuffer values, DataBuffer rowInd, DataBuffer colInd, int nnz, INDArray x, INDArray y){ mkl_cspblas_scoogemv( Character.toString(transA), (IntPointer) Nd4j.createBuffer(new int[]{M}).addressPointer(), (FloatPointer) values.addressPointer(), (IntPointer) rowInd.addressPointer(), (IntPointer) colInd.addressPointer(), (IntPointer) Nd4j.createBuffer(new int[]{nnz}).addressPointer(), (FloatPointer) x.data().addressPointer(), (FloatPointer)y.data().addressPointer()); }
Example #19
Source File: AbstractCompressor.java From nd4j with Apache License 2.0 | 5 votes |
/** * This method creates compressed INDArray from Java float array, skipping usual INDArray instantiation routines * * @param data * @param shape * @param order * @return */ @Override public INDArray compress(float[] data, int[] shape, char order) { FloatPointer pointer = new FloatPointer(data); DataBuffer shapeInfo = Nd4j.getShapeInfoProvider().createShapeInformation(shape, order).getFirst(); DataBuffer buffer = compressPointer(DataBuffer.TypeEx.FLOAT, pointer, data.length, 4); return Nd4j.createArrayFromShapeBuffer(buffer, shapeInfo); }
Example #20
Source File: CpuLevel3.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void sgemm(char Order, char TransA, char TransB, int M, int N, int K, float alpha, INDArray A, int lda, INDArray B, int ldb, float beta, INDArray C, int ldc) { if (!Nd4j.isFallbackModeEnabled()) { cblas_sgemm(convertOrder('f'), convertTranspose(TransA), convertTranspose(TransB), M, N, K, alpha, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) B.data().addressPointer(), ldb, beta, (FloatPointer) C.data().addressPointer(), ldc); } else { Nd4j.getExecutioner() .exec(new AggregateGEMM('f', TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc)); } }
Example #21
Source File: CpuLevel3.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void ssymm(char Order, char Side, char Uplo, int M, int N, float alpha, INDArray A, int lda, INDArray B, int ldb, float beta, INDArray C, int ldc) { cblas_ssymm(convertOrder('f'), convertSide(Side), convertUplo(Uplo), M, N, alpha, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) B.data().addressPointer(), ldb, beta, (FloatPointer) C.data().addressPointer(), ldc); }
Example #22
Source File: CpuLevel3.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void ssyrk(char Order, char Uplo, char Trans, int N, int K, float alpha, INDArray A, int lda, float beta, INDArray C, int ldc) { cblas_ssyrk(convertOrder('f'), convertUplo(Uplo), convertTranspose(Trans), N, K, alpha, (FloatPointer) A.data().addressPointer(), lda, beta, (FloatPointer) C.data().addressPointer(), ldc); }
Example #23
Source File: CpuLevel3.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void ssyr2k(char Order, char Uplo, char Trans, int N, int K, float alpha, INDArray A, int lda, INDArray B, int ldb, float beta, INDArray C, int ldc) { cblas_ssyr2k(convertOrder('f'), convertUplo(Uplo), convertTranspose(Trans), N, K, alpha, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) B.data().addressPointer(), ldb, beta, (FloatPointer) C.data().addressPointer(), ldc); }
Example #24
Source File: CpuLevel3.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void strsm(char Order, char Side, char Uplo, char TransA, char Diag, int M, int N, float alpha, INDArray A, int lda, INDArray B, int ldb) { cblas_strsm(convertOrder('f'), convertSide(Side), convertUplo(Uplo), convertTranspose(TransA), Diag, M, N, alpha, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) B.data().addressPointer(), ldb); }
Example #25
Source File: DefaultDataBufferFactory.java From nd4j with Apache License 2.0 | 5 votes |
/** * @param floatPointer * @param length * @return */ @Override public DataBuffer create(FloatPointer floatPointer, long length) { floatPointer.capacity(length); floatPointer.limit(length); floatPointer.position(0); return new FloatBuffer(floatPointer, FloatIndexer.create(floatPointer), length); }
Example #26
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void sgbmv(char order, char TransA, int M, int N, int KL, int KU, float alpha, INDArray A, int lda, INDArray X, int incX, float beta, INDArray Y, int incY) { cblas_sgbmv(convertOrder('f'), convertTranspose(TransA), M, N, KL, KU, alpha, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) X.data().addressPointer(), incX, beta, (FloatPointer) Y.data().addressPointer(), incY); }
Example #27
Source File: CpuLevel2.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override protected void sgemv(char order, char TransA, int M, int N, float alpha, INDArray A, int lda, INDArray X, int incX, float beta, INDArray Y, int incY) { cblas_sgemv(convertOrder('f'), convertTranspose(TransA), M, N, alpha, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) X.data().addressPointer(), incX, beta, (FloatPointer) Y.data().addressPointer(), incY); }
Example #28
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void ssymv(char order, char Uplo, int N, float alpha, INDArray A, int lda, INDArray X, int incX, float beta, INDArray Y, int incY) { cblas_ssymv(convertOrder('f'), convertUplo(Uplo), N, alpha, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) X.data().addressPointer(), incX, beta, (FloatPointer) Y.data().addressPointer(), incY); }
Example #29
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void sspmv(char order, char Uplo, int N, float alpha, INDArray Ap, INDArray X, int incX, float beta, INDArray Y, int incY) { cblas_sspmv(convertOrder('f'), convertUplo(Uplo), N, alpha, (FloatPointer) Ap.data().addressPointer(), (FloatPointer) X.data().addressPointer(), incX, beta, (FloatPointer) Y.data().addressPointer(), incY); }
Example #30
Source File: CpuLevel2.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override protected void sgbmv(char order, char TransA, int M, int N, int KL, int KU, float alpha, INDArray A, int lda, INDArray X, int incX, float beta, INDArray Y, int incY) { cblas_sgbmv(convertOrder('f'), convertTranspose(TransA), M, N, KL, KU, alpha, (FloatPointer) A.data().addressPointer(), lda, (FloatPointer) X.data().addressPointer(), incX, beta, (FloatPointer) Y.data().addressPointer(), incY); }