From 4fe2416c8074e388644c217e041c5d6a2b2c799b Mon Sep 17 00:00:00 2001 From: minmingzhu Date: Mon, 19 Aug 2024 14:48:10 +0800 Subject: [PATCH] update code style and unit test --- mllib-dal/src/main/native/CorrelationImpl.cpp | 6 +++--- .../src/main/native/DecisionForestClassifierImpl.cpp | 8 ++++---- .../src/main/native/DecisionForestRegressorImpl.cpp | 11 ++++++----- mllib-dal/src/main/native/KMeansImpl.cpp | 8 ++++---- mllib-dal/src/main/native/LinearRegressionImpl.cpp | 11 +++++------ mllib-dal/src/main/native/PCAImpl.cpp | 6 +++--- mllib-dal/src/main/native/SummarizerImpl.cpp | 9 +++++---- .../oap/mllib/CorrelationHomogenTableSuite.scala | 2 +- .../com/intel/oap/mllib/KmeansHomogenTableSuite.scala | 2 +- .../com/intel/oap/mllib/PCAHomogenTableSuite.scala | 4 ++-- .../intel/oap/mllib/SummarizerHomogenTableSuite.scala | 2 +- 11 files changed, 35 insertions(+), 34 deletions(-) diff --git a/mllib-dal/src/main/native/CorrelationImpl.cpp b/mllib-dal/src/main/native/CorrelationImpl.cpp index a9103102f..5f4b47cfd 100644 --- a/mllib-dal/src/main/native/CorrelationImpl.cpp +++ b/mllib-dal/src/main/native/CorrelationImpl.cpp @@ -197,9 +197,9 @@ static void doCorrelationOneAPICompute( JNIEXPORT jlong JNICALL Java_com_intel_oap_mllib_stat_CorrelationDALImpl_cCorrelationTrainDAL( - JNIEnv *env, jobject obj, jint rank, jlong pNumTabData, jlong numRows, jlong numCols, - jint executorNum, jint executorCores, jint computeDeviceOrdinal, - jintArray gpuIdxArray, jobject resultObj) { + JNIEnv *env, jobject obj, jint rank, jlong pNumTabData, jlong numRows, + jlong numCols, jint executorNum, jint executorCores, + jint computeDeviceOrdinal, jintArray gpuIdxArray, jobject resultObj) { logger::println(logger::INFO, "oneDAL (native): use DPC++ kernels; device %s", ComputeDeviceString[computeDeviceOrdinal].c_str()); diff --git a/mllib-dal/src/main/native/DecisionForestClassifierImpl.cpp b/mllib-dal/src/main/native/DecisionForestClassifierImpl.cpp index aad8d9048..f383eb7b9 100644 --- a/mllib-dal/src/main/native/DecisionForestClassifierImpl.cpp +++ b/mllib-dal/src/main/native/DecisionForestClassifierImpl.cpp @@ -300,10 +300,10 @@ static jobject doRFClassifierOneAPICompute( */ JNIEXPORT jobject JNICALL Java_com_intel_oap_mllib_classification_RandomForestClassifierDALImpl_cRFClassifierTrainDAL( - JNIEnv *env, jobject obj, jint rank, jlong pNumTabFeature, jlong featureRows, - jlong featureCols, jlong pNumTabLabel, jlong labelCols, jint executorNum, - jint computeDeviceOrdinal, jint classCount, jint treeCount, - jint numFeaturesPerNode, jint minObservationsLeafNode, + JNIEnv *env, jobject obj, jint rank, jlong pNumTabFeature, + jlong featureRows, jlong featureCols, jlong pNumTabLabel, jlong labelCols, + jint executorNum, jint computeDeviceOrdinal, jint classCount, + jint treeCount, jint numFeaturesPerNode, jint minObservationsLeafNode, jint minObservationsSplitNode, jdouble minWeightFractionLeafNode, jdouble minImpurityDecreaseSplitNode, jint maxTreeDepth, jlong seed, jint maxBins, jboolean bootstrap, jintArray gpuIdxArray, diff --git a/mllib-dal/src/main/native/DecisionForestRegressorImpl.cpp b/mllib-dal/src/main/native/DecisionForestRegressorImpl.cpp index 853f736de..ca1fb2aaa 100644 --- a/mllib-dal/src/main/native/DecisionForestRegressorImpl.cpp +++ b/mllib-dal/src/main/native/DecisionForestRegressorImpl.cpp @@ -292,11 +292,12 @@ static jobject doRFRegressorOneAPICompute( JNIEXPORT jobject JNICALL Java_com_intel_oap_mllib_regression_RandomForestRegressorDALImpl_cRFRegressorTrainDAL( - JNIEnv *env, jobject obj, jint rank, jlong pNumTabFeature, jlong featureRows, - jlong featureCols, jlong pNumTabLabel, jlong labelCols, jint executorNum, - jint computeDeviceOrdinal, jint treeCount, jint numFeaturesPerNode, - jint minObservationsLeafNode, jint maxTreeDepth, jlong seed, jint maxbins, - jboolean bootstrap, jintArray gpuIdxArray, jobject resultObj) { + JNIEnv *env, jobject obj, jint rank, jlong pNumTabFeature, + jlong featureRows, jlong featureCols, jlong pNumTabLabel, jlong labelCols, + jint executorNum, jint computeDeviceOrdinal, jint treeCount, + jint numFeaturesPerNode, jint minObservationsLeafNode, jint maxTreeDepth, + jlong seed, jint maxbins, jboolean bootstrap, jintArray gpuIdxArray, + jobject resultObj) { logger::println(logger::INFO, "OneDAL (native): use DPC++ kernels; device %s", ComputeDeviceString[computeDeviceOrdinal].c_str()); diff --git a/mllib-dal/src/main/native/KMeansImpl.cpp b/mllib-dal/src/main/native/KMeansImpl.cpp index f690c1c45..9a3ce8550 100644 --- a/mllib-dal/src/main/native/KMeansImpl.cpp +++ b/mllib-dal/src/main/native/KMeansImpl.cpp @@ -305,10 +305,10 @@ static jlong doKMeansOneAPICompute( */ JNIEXPORT jlong JNICALL Java_com_intel_oap_mllib_clustering_KMeansDALImpl_cKMeansOneapiComputeWithInitCenters( - JNIEnv *env, jobject obj, jint rank, jlong pNumTabData, jlong numRows, jlong numCols, - jlong pNumTabCenters, jint clusterNum, jdouble tolerance, jint iterationNum, - jint executorNum, jint executorCores, jint computeDeviceOrdinal, - jintArray gpuIdxArray, jobject resultObj) { + JNIEnv *env, jobject obj, jint rank, jlong pNumTabData, jlong numRows, + jlong numCols, jlong pNumTabCenters, jint clusterNum, jdouble tolerance, + jint iterationNum, jint executorNum, jint executorCores, + jint computeDeviceOrdinal, jintArray gpuIdxArray, jobject resultObj) { logger::println(logger::INFO, "OneDAL (native): use DPC++ kernels; device %s", ComputeDeviceString[computeDeviceOrdinal].c_str()); diff --git a/mllib-dal/src/main/native/LinearRegressionImpl.cpp b/mllib-dal/src/main/native/LinearRegressionImpl.cpp index b82feb358..21ab41546 100644 --- a/mllib-dal/src/main/native/LinearRegressionImpl.cpp +++ b/mllib-dal/src/main/native/LinearRegressionImpl.cpp @@ -214,8 +214,7 @@ ridge_regression_compute(size_t rankId, ccl::communicator &comm, } #ifdef CPU_GPU_PROFILE -static jlong doLROneAPICompute(JNIEnv *env, size_t rankId, - sycl::queue &queue, +static jlong doLROneAPICompute(JNIEnv *env, size_t rankId, sycl::queue &queue, jlong pNumTabFeature, jlong featureRows, jlong featureCols, jlong pNumTabLabel, jlong labelCols, jboolean jfitIntercept, @@ -289,9 +288,9 @@ Java_com_intel_oap_mllib_regression_LinearRegressionDALImpl_cLinearRegressionTra jint *gpuIndices = env->GetIntArrayElements(gpuIdxArray, 0); auto queue = getAssignedGPU(device, gpuIndices); - resultptr = doLROneAPICompute( - env, rank, queue, feature, featureRows, featureCols, - label, labelCols, fitIntercept, executorNum, resultObj); + resultptr = doLROneAPICompute(env, rank, queue, feature, featureRows, + featureCols, label, labelCols, + fitIntercept, executorNum, resultObj); env->ReleaseIntArrayElements(gpuIdxArray, gpuIndices, 0); #endif } else { @@ -320,7 +319,7 @@ Java_com_intel_oap_mllib_regression_LinearRegressionDALImpl_cLinearRegressionTra NumericTablePtr *coeffvectors = new NumericTablePtr(resultTable); resultptr = (jlong)coeffvectors; - if (rankId == ccl_root) { + if (rankId == ccl_root) { // Get the class of the result object jclass clazz = env->GetObjectClass(resultObj); // Get Field references diff --git a/mllib-dal/src/main/native/PCAImpl.cpp b/mllib-dal/src/main/native/PCAImpl.cpp index f2821d558..743d07fbf 100644 --- a/mllib-dal/src/main/native/PCAImpl.cpp +++ b/mllib-dal/src/main/native/PCAImpl.cpp @@ -250,9 +250,9 @@ static void doPCAOneAPICompute( JNIEXPORT jlong JNICALL Java_com_intel_oap_mllib_feature_PCADALImpl_cPCATrainDAL( - JNIEnv *env, jobject obj, jint rank, jlong pNumTabData, jlong numRows, jlong numCols, - jint executorNum, jint executorCores, jint computeDeviceOrdinal, - jintArray gpuIdxArray, jobject resultObj) { + JNIEnv *env, jobject obj, jint rank, jlong pNumTabData, jlong numRows, + jlong numCols, jint executorNum, jint executorCores, + jint computeDeviceOrdinal, jintArray gpuIdxArray, jobject resultObj) { logger::println(logger::INFO, "oneDAL (native): use DPC++ kernels; device %s", ComputeDeviceString[computeDeviceOrdinal].c_str()); diff --git a/mllib-dal/src/main/native/SummarizerImpl.cpp b/mllib-dal/src/main/native/SummarizerImpl.cpp index 9af30d939..37ae93256 100644 --- a/mllib-dal/src/main/native/SummarizerImpl.cpp +++ b/mllib-dal/src/main/native/SummarizerImpl.cpp @@ -268,9 +268,9 @@ static void doSummarizerOneAPICompute( JNIEXPORT jlong JNICALL Java_com_intel_oap_mllib_stat_SummarizerDALImpl_cSummarizerTrainDAL( - JNIEnv *env, jobject obj, jint rank, jlong pNumTabData, jlong numRows, jlong numCols, - jint executorNum, jint executorCores, jint computeDeviceOrdinal, - jintArray gpuIdxArray, jobject resultObj) { + JNIEnv *env, jobject obj, jint rank, jlong pNumTabData, jlong numRows, + jlong numCols, jint executorNum, jint executorCores, + jint computeDeviceOrdinal, jintArray gpuIdxArray, jobject resultObj) { logger::println(logger::INFO, "oneDAL (native): use DPC++ kernels; device %s", ComputeDeviceString[computeDeviceOrdinal].c_str()); @@ -315,7 +315,8 @@ Java_com_intel_oap_mllib_stat_SummarizerDALImpl_cSummarizerTrainDAL( } #endif default: { - deviceError("Summarizer", ComputeDeviceString[computeDeviceOrdinal].c_str()); + deviceError("Summarizer", + ComputeDeviceString[computeDeviceOrdinal].c_str()); } } return 0; diff --git a/mllib-dal/src/test/scala/com/intel/oap/mllib/CorrelationHomogenTableSuite.scala b/mllib-dal/src/test/scala/com/intel/oap/mllib/CorrelationHomogenTableSuite.scala index 34361766d..ecbb8f43a 100644 --- a/mllib-dal/src/test/scala/com/intel/oap/mllib/CorrelationHomogenTableSuite.scala +++ b/mllib-dal/src/test/scala/com/intel/oap/mllib/CorrelationHomogenTableSuite.scala @@ -45,7 +45,7 @@ class CorrelationHomogenTableSuite extends FunctionsSuite with Logging { val correlationDAL = new CorrelationDALImpl(1, 1) val gpuIndices = Array(0) val result = new CorrelationResult() - correlationDAL.cCorrelationTrainDAL(dataTable.getcObejct(), sourceData.length, sourceData(0).length, 1, 1, Common.ComputeDevice.HOST.ordinal(), gpuIndices, result); + correlationDAL.cCorrelationTrainDAL(0, dataTable.getcObejct(), sourceData.length, sourceData(0).length, 1, 1, Common.ComputeDevice.HOST.ordinal(), gpuIndices, result); val correlationMatrix = TestCommon.getMatrixFromTable(OneDAL.makeHomogenTable( result.getCorrelationNumericTable), TestCommon.getComputeDevice) diff --git a/mllib-dal/src/test/scala/com/intel/oap/mllib/KmeansHomogenTableSuite.scala b/mllib-dal/src/test/scala/com/intel/oap/mllib/KmeansHomogenTableSuite.scala index 63f92711b..96b8e7231 100644 --- a/mllib-dal/src/test/scala/com/intel/oap/mllib/KmeansHomogenTableSuite.scala +++ b/mllib-dal/src/test/scala/com/intel/oap/mllib/KmeansHomogenTableSuite.scala @@ -49,7 +49,7 @@ class KmeansHomogenTableSuite extends FunctionsSuite with Logging { OneCCL.init(1, 1, "127.0.0.1_3000") val gpuIndices = Array(0) val result = new KMeansResult(); - val centroids = kmeansDAL.cKMeansOneapiComputeWithInitCenters(dataTable.getcObejct(), sourceData.length, sourceData(0).length, centroidsTable.getcObejct(),10, 0.001, + val centroids = kmeansDAL.cKMeansOneapiComputeWithInitCenters(0, dataTable.getcObejct(), sourceData.length, sourceData(0).length, centroidsTable.getcObejct(),10, 0.001, 5, 1, 1, TestCommon.getComputeDevice.ordinal(), gpuIndices, result); val resultVectors = OneDAL.homogenTableToVectors(OneDAL.makeHomogenTable(centroids), TestCommon.getComputeDevice); assertArrayEquals(TestCommon.convertArray(expectCentroids), TestCommon.convertArray(resultVectors), 0.000001) diff --git a/mllib-dal/src/test/scala/com/intel/oap/mllib/PCAHomogenTableSuite.scala b/mllib-dal/src/test/scala/com/intel/oap/mllib/PCAHomogenTableSuite.scala index e004212df..5097800bc 100644 --- a/mllib-dal/src/test/scala/com/intel/oap/mllib/PCAHomogenTableSuite.scala +++ b/mllib-dal/src/test/scala/com/intel/oap/mllib/PCAHomogenTableSuite.scala @@ -47,7 +47,7 @@ class PCAHomogenTableSuite extends FunctionsSuite with Logging { val pcaDAL = new PCADALImpl(5, 1, 1) val gpuIndices = Array(0) val result = new PCAResult() - pcaDAL.cPCATrainDAL(dataTable.getcObejct(), sourceData.length, sourceData(0).length, 1, 1, TestCommon.getComputeDevice.ordinal(), gpuIndices, result); + pcaDAL.cPCATrainDAL(0, dataTable.getcObejct(), sourceData.length, sourceData(0).length, 1, 1, TestCommon.getComputeDevice.ordinal(), gpuIndices, result); val pcNumericTable = OneDAL.makeHomogenTable(result.getPcNumericTable) val explainedVarianceNumericTable = OneDAL.makeHomogenTable( result.getExplainedVarianceNumericTable) @@ -79,7 +79,7 @@ class PCAHomogenTableSuite extends FunctionsSuite with Logging { val pcaDAL = new PCADALImpl(5, 1, 1) val gpuIndices = Array(0) val result = new PCAResult() - pcaDAL.cPCATrainDAL(dataTable.getcObejct(), sourceData.length, sourceData(0).length, 1, 1, TestCommon.getComputeDevice.ordinal(), gpuIndices, result); + pcaDAL.cPCATrainDAL(0, dataTable.getcObejct(), sourceData.length, sourceData(0).length, 1, 1, TestCommon.getComputeDevice.ordinal(), gpuIndices, result); val pcNumericTable = OneDAL.makeHomogenTable(result.getPcNumericTable) val explainedVarianceNumericTable = OneDAL.makeHomogenTable( result.getExplainedVarianceNumericTable) diff --git a/mllib-dal/src/test/scala/com/intel/oap/mllib/SummarizerHomogenTableSuite.scala b/mllib-dal/src/test/scala/com/intel/oap/mllib/SummarizerHomogenTableSuite.scala index 712cccbfa..0c8b516e1 100644 --- a/mllib-dal/src/test/scala/com/intel/oap/mllib/SummarizerHomogenTableSuite.scala +++ b/mllib-dal/src/test/scala/com/intel/oap/mllib/SummarizerHomogenTableSuite.scala @@ -35,7 +35,7 @@ class SummarizerHomogenTableSuite extends FunctionsSuite with Logging{ val summarizerDAL = new SummarizerDALImpl(1, 1) val gpuIndices = Array(0) val result = new SummarizerResult() - summarizerDAL.cSummarizerTrainDAL(dataTable.getcObejct(), sourceData.length, sourceData(0).length, 1, 1, Common.ComputeDevice.HOST.ordinal(), gpuIndices, result) + summarizerDAL.cSummarizerTrainDAL(0, dataTable.getcObejct(), sourceData.length, sourceData(0).length, 1, 1, Common.ComputeDevice.HOST.ordinal(), gpuIndices, result) val meanTable = OneDAL.homogenTable1xNToVector(OneDAL.makeHomogenTable(result.getMeanNumericTable), Common.ComputeDevice.HOST) val varianceTable = OneDAL.homogenTable1xNToVector(OneDAL.makeHomogenTable(result.getVarianceNumericTable), Common.ComputeDevice.HOST) val minimumTable = OneDAL.homogenTable1xNToVector(OneDAL.makeHomogenTable(result.getMinimumNumericTable), Common.ComputeDevice.HOST)