diff --git a/mllib-dal/src/main/java/com/intel/oneapi/dal/table/ColumnAccessor.java b/mllib-dal/src/main/java/com/intel/oneapi/dal/table/ColumnAccessor.java index 345b8b6e6..83f81c8d0 100644 --- a/mllib-dal/src/main/java/com/intel/oneapi/dal/table/ColumnAccessor.java +++ b/mllib-dal/src/main/java/com/intel/oneapi/dal/table/ColumnAccessor.java @@ -4,6 +4,11 @@ public class ColumnAccessor { private long cObject; private Common.ComputeDevice cDevice; + public ColumnAccessor(long cObject) { + this.cObject = cObject; + this.cDevice = Common.ComputeDevice.HOST; + } + public ColumnAccessor(long cObject, Common.ComputeDevice device) { this.cObject = cObject; this.cDevice = device; diff --git a/mllib-dal/src/main/java/com/intel/oneapi/dal/table/RowAccessor.java b/mllib-dal/src/main/java/com/intel/oneapi/dal/table/RowAccessor.java index b430934cf..e63389214 100644 --- a/mllib-dal/src/main/java/com/intel/oneapi/dal/table/RowAccessor.java +++ b/mllib-dal/src/main/java/com/intel/oneapi/dal/table/RowAccessor.java @@ -3,6 +3,11 @@ public class RowAccessor { private long cObject; private Common.ComputeDevice cDevice; + public RowAccessor(long cObject) { + this.cObject = cObject; + this.cDevice = Common.ComputeDevice.HOST; + } + public RowAccessor(long cObject, Common.ComputeDevice device) { this.cObject = cObject; this.cDevice = device; diff --git a/mllib-dal/src/main/scala/com/intel/oap/mllib/OneDAL.scala b/mllib-dal/src/main/scala/com/intel/oap/mllib/OneDAL.scala index 5c781cf4e..12847d691 100644 --- a/mllib-dal/src/main/scala/com/intel/oap/mllib/OneDAL.scala +++ b/mllib-dal/src/main/scala/com/intel/oap/mllib/OneDAL.scala @@ -69,11 +69,11 @@ object OneDAL { matrix } - def homogenTableToMatrix(table: HomogenTable, device: Common.ComputeDevice): Matrix = { + def homogenTableToMatrix(table: HomogenTable): Matrix = { val numRows = table.getRowCount.toInt val numCols = table.getColumnCount.toInt - val accessor = new RowAccessor(table.getcObejct(), device) + val accessor = new RowAccessor(table.getcObejct()) val arrayDouble: Array[Double] = accessor.pullDouble(0, numRows) // Transpose as DAL numeric table is row-major and DenseMatrix is column major @@ -82,11 +82,11 @@ object OneDAL { matrix } - def homogenTableToOldMatrix(table: HomogenTable, device: Common.ComputeDevice): OldMatrix = { + def homogenTableToOldMatrix(table: HomogenTable): OldMatrix = { val numRows = table.getRowCount.toInt val numCols = table.getColumnCount.toInt - val accessor = new RowAccessor(table.getcObejct(), device) + val accessor = new RowAccessor(table.getcObejct()) val arrayDouble: Array[Double] = accessor.pullDouble(0, numRows) // Transpose as DAL numeric table is row-major and DenseMatrix is column major @@ -115,8 +115,8 @@ object OneDAL { Vectors.dense(arrayDouble) } - def homogenTableNx1ToVector(cTable: Long, device: Common.ComputeDevice ): Vector = { - val columnAcc = new ColumnAccessor(cTable, device) + def homogenTableNx1ToVector(cTable: Long): Vector = { + val columnAcc = new ColumnAccessor(cTable) val arrayDouble = columnAcc.pullDouble(0) Vectors.dense(arrayDouble) } @@ -135,8 +135,8 @@ object OneDAL { Vectors.dense(arrayDouble) } - def homogenTable1xNToVector(table: HomogenTable, device: Common.ComputeDevice): Vector = { - val rowAcc = new RowAccessor(table.getcObejct, device) + def homogenTable1xNToVector(table: HomogenTable): Vector = { + val rowAcc = new RowAccessor(table.getcObejct) val arrayDouble = rowAcc.pullDouble(0, 1) Vectors.dense(arrayDouble) } @@ -159,10 +159,10 @@ object OneDAL { resArray } - def homogenTableToVectors(table: HomogenTable, device: Common.ComputeDevice): Array[Vector] = { + def homogenTableToVectors(table: HomogenTable): Array[Vector] = { val numRows = table.getRowCount.toInt - val rowAcc = new RowAccessor(table.getcObejct(), device) + val rowAcc = new RowAccessor(table.getcObejct()) val resArray = new Array[Vector](numRows.toInt) diff --git a/mllib-dal/src/main/scala/com/intel/oap/mllib/clustering/KMeansDALImpl.scala b/mllib-dal/src/main/scala/com/intel/oap/mllib/clustering/KMeansDALImpl.scala index e194e9d22..95a3a5570 100644 --- a/mllib-dal/src/main/scala/com/intel/oap/mllib/clustering/KMeansDALImpl.scala +++ b/mllib-dal/src/main/scala/com/intel/oap/mllib/clustering/KMeansDALImpl.scala @@ -98,8 +98,7 @@ class KMeansDALImpl(var nClusters: Int, val ret = if (rank == 0) { assert(cCentroids != 0) val centerVectors = if (useDevice == "GPU") { - OneDAL.homogenTableToVectors(OneDAL.makeHomogenTable(cCentroids), - computeDevice) + OneDAL.homogenTableToVectors(OneDAL.makeHomogenTable(cCentroids)) } else { OneDAL.numericTableToVectors(OneDAL.makeNumericTable(cCentroids)) } diff --git a/mllib-dal/src/main/scala/com/intel/oap/mllib/feature/PCADALImpl.scala b/mllib-dal/src/main/scala/com/intel/oap/mllib/feature/PCADALImpl.scala index 0410c18a7..1744e4275 100644 --- a/mllib-dal/src/main/scala/com/intel/oap/mllib/feature/PCADALImpl.scala +++ b/mllib-dal/src/main/scala/com/intel/oap/mllib/feature/PCADALImpl.scala @@ -92,7 +92,7 @@ class PCADALImpl(val k: Int, val ret = if (rank == 0) { val principleComponents = if (useDevice == "GPU") { val pcNumericTable = OneDAL.makeHomogenTable(result.getPcNumericTable) - getPrincipleComponentsFromOneAPI(pcNumericTable, k, computeDevice) + getPrincipleComponentsFromOneAPI(pcNumericTable, k) } else { val pcNumericTable = OneDAL.makeNumericTable(result.getPcNumericTable) getPrincipleComponentsFromDAL(pcNumericTable, k) @@ -102,7 +102,7 @@ class PCADALImpl(val k: Int, val explainedVarianceNumericTable = OneDAL.makeHomogenTable( result.getExplainedVarianceNumericTable) getExplainedVarianceFromOneAPI( - explainedVarianceNumericTable, k, computeDevice) + explainedVarianceNumericTable, k) } else { val explainedVarianceNumericTable = OneDAL.makeNumericTable( result.getExplainedVarianceNumericTable) @@ -141,21 +141,20 @@ class PCADALImpl(val k: Int, } private[mllib] def getPrincipleComponentsFromOneAPI(table: HomogenTable, - k: Int, - device: Common.ComputeDevice): DenseMatrix = { + k: Int): DenseMatrix = { val numRows = table.getRowCount.toInt val numCols = table.getColumnCount.toInt require(k <= numRows, "k should be less or equal to row number") - val arrayDouble = getDoubleBufferDataFromOneAPI(table, numRows, device) + val arrayDouble = getDoubleBufferDataFromOneAPI(table, numRows) // Column-major, transpose of top K rows of NumericTable new DenseMatrix(numCols, k, arrayDouble.slice(0, numCols * k), false) } - private[mllib] def getExplainedVarianceFromOneAPI(table_1xn: HomogenTable, k: Int, - device: Common.ComputeDevice): DenseVector = { - val arrayDouble = getDoubleBufferDataFromOneAPI(table_1xn, 1, device) + private[mllib] def getExplainedVarianceFromOneAPI(table_1xn: HomogenTable, + k: Int): DenseVector = { + val arrayDouble = getDoubleBufferDataFromOneAPI(table_1xn, 1) val sum = arrayDouble.sum val topK = Arrays.copyOfRange(arrayDouble, 0, k) for (i <- 0 until k) @@ -166,11 +165,10 @@ class PCADALImpl(val k: Int, // table.asInstanceOf[HomogenNumericTable].getDoubleArray() would error on GPU, // so use table.getBlockOfRows instead of it. private[mllib] def getDoubleBufferDataFromOneAPI(table: HomogenTable, - numRows: Int, - device: Common.ComputeDevice): Array[Double] = { + numRows: Int): Array[Double] = { // returned DoubleBuffer is ByteByffer, need to copy as double array - val accessor = new RowAccessor(table.getcObejct(), device) + val accessor = new RowAccessor(table.getcObejct()) val arrayDouble: Array[Double] = accessor.pullDouble(0, numRows) arrayDouble diff --git a/mllib-dal/src/main/scala/com/intel/oap/mllib/regression/LinearRegressionDALImpl.scala b/mllib-dal/src/main/scala/com/intel/oap/mllib/regression/LinearRegressionDALImpl.scala index 806fdb40c..10f3db5d3 100644 --- a/mllib-dal/src/main/scala/com/intel/oap/mllib/regression/LinearRegressionDALImpl.scala +++ b/mllib-dal/src/main/scala/com/intel/oap/mllib/regression/LinearRegressionDALImpl.scala @@ -155,8 +155,7 @@ class LinearRegressionDALImpl( val fitIntercept: Boolean, val ret = if (rank == 0) { val coefficientArray = if (useDevice == "GPU") { - OneDAL.homogenTableToVectors(OneDAL.makeHomogenTable(cbeta), - computeDevice) + OneDAL.homogenTableToVectors(OneDAL.makeHomogenTable(cbeta)) } else { OneDAL.numericTableToVectors(OneDAL.makeNumericTable(cbeta)) } diff --git a/mllib-dal/src/main/scala/com/intel/oap/mllib/regression/RandomForestRegressorDALImpl.scala b/mllib-dal/src/main/scala/com/intel/oap/mllib/regression/RandomForestRegressorDALImpl.scala index 16fd17cdb..d9d331080 100644 --- a/mllib-dal/src/main/scala/com/intel/oap/mllib/regression/RandomForestRegressorDALImpl.scala +++ b/mllib-dal/src/main/scala/com/intel/oap/mllib/regression/RandomForestRegressorDALImpl.scala @@ -117,8 +117,7 @@ class RandomForestRegressorDALImpl(val uid: String, val ret = if (rank == 0) { val convResultStartTime = System.nanoTime() val predictionNumericTable = OneDAL.homogenTableToMatrix( - OneDAL.makeHomogenTable(result.getPredictionNumericTable), - computeDevice) + OneDAL.makeHomogenTable(result.getPredictionNumericTable)) val convResultEndTime = System.nanoTime() val durationCovResult = (convResultEndTime - convResultStartTime).toDouble / 1E9 diff --git a/mllib-dal/src/main/scala/com/intel/oap/mllib/stat/CorrelationDALImpl.scala b/mllib-dal/src/main/scala/com/intel/oap/mllib/stat/CorrelationDALImpl.scala index 21465e1af..0ecbe0f6d 100644 --- a/mllib-dal/src/main/scala/com/intel/oap/mllib/stat/CorrelationDALImpl.scala +++ b/mllib-dal/src/main/scala/com/intel/oap/mllib/stat/CorrelationDALImpl.scala @@ -88,8 +88,7 @@ class CorrelationDALImpl( val ret = if (rank == 0) { val convResultStartTime = System.nanoTime() val correlationNumericTable = if (useDevice == "GPU") { - OneDAL.homogenTableToMatrix(OneDAL.makeHomogenTable(result.getCorrelationNumericTable), - computeDevice) + OneDAL.homogenTableToMatrix(OneDAL.makeHomogenTable(result.getCorrelationNumericTable)) } else { OneDAL.numericTableToMatrix(OneDAL.makeNumericTable(result.getCorrelationNumericTable)) } diff --git a/mllib-dal/src/main/scala/com/intel/oap/mllib/stat/SummarizerDALImpl.scala b/mllib-dal/src/main/scala/com/intel/oap/mllib/stat/SummarizerDALImpl.scala index a516962c3..b47bdb04e 100644 --- a/mllib-dal/src/main/scala/com/intel/oap/mllib/stat/SummarizerDALImpl.scala +++ b/mllib-dal/src/main/scala/com/intel/oap/mllib/stat/SummarizerDALImpl.scala @@ -91,28 +91,28 @@ class SummarizerDALImpl(val executorNum: Int, val convResultStartTime = System.nanoTime() val meanVector = if (useDevice == "GPU") { OneDAL.homogenTable1xNToVector( - OneDAL.makeHomogenTable(result.getMeanNumericTable), computeDevice) + OneDAL.makeHomogenTable(result.getMeanNumericTable)) } else { OneDAL.numericTable1xNToVector( OneDAL.makeNumericTable(result.getMeanNumericTable)) } val varianceVector = if (useDevice == "GPU") { OneDAL.homogenTable1xNToVector( - OneDAL.makeHomogenTable(result.getVarianceNumericTable), computeDevice) + OneDAL.makeHomogenTable(result.getVarianceNumericTable)) } else { OneDAL.numericTable1xNToVector( OneDAL.makeNumericTable(result.getVarianceNumericTable)) } val maxVector = if (useDevice == "GPU") { OneDAL.homogenTable1xNToVector( - OneDAL.makeHomogenTable(result.getMaximumNumericTable), computeDevice) + OneDAL.makeHomogenTable(result.getMaximumNumericTable)) } else { OneDAL.numericTable1xNToVector( OneDAL.makeNumericTable(result.getMaximumNumericTable)) } val minVector = if (useDevice == "GPU") { OneDAL.homogenTable1xNToVector( - OneDAL.makeHomogenTable(result.getMinimumNumericTable), computeDevice) + OneDAL.makeHomogenTable(result.getMinimumNumericTable)) } else { OneDAL.numericTable1xNToVector( OneDAL.makeNumericTable(result.getMinimumNumericTable))