mnemonic-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [02/14] incubator-mnemonic git commit: MNEMONIC-160: add optimized 1d long bubble sorting
Date Mon, 21 Nov 2016 17:32:28 GMT
MNEMONIC-160: add optimized 1d long bubble sorting


Project: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/commit/0c0a20dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/tree/0c0a20dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/diff/0c0a20dc

Branch: refs/heads/master
Commit: 0c0a20dc4d96931944d09469306f9d38180c8517
Parents: e2eb6b0
Author: Wang, Gang(Gary) <gang1.wang@intel.com>
Authored: Mon Nov 14 11:48:23 2016 -0800
Committer: Wang, Gang(Gary) <gang1.wang@intel.com>
Committed: Thu Nov 17 12:48:22 2016 -0800

----------------------------------------------------------------------
 .../internal/SortServiceImpl.java               |   4 +
 .../src/main/native/CMakeLists.txt              |   2 +-
 ..._computingservice_internal_SortServiceImpl.c | 112 +++++++++++++++++++
 3 files changed, 117 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/0c0a20dc/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/SortServiceImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/SortServiceImpl.java
b/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/SortServiceImpl.java
index ffa99d1..b866506 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/SortServiceImpl.java
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/SortServiceImpl.java
@@ -47,6 +47,8 @@ public class SortServiceImpl implements GeneralComputingService {
     if (null != mode && null != valinfos) {
       if ("tensor_bubble".equals(mode)) {
         ret = nperformBubbleSort(valinfos);
+      } else if ("1dlong_bubble".equals(mode)) {
+        ret = nperform1DLongBubbleSort(valinfos);
       }
     }
     return ret;
@@ -59,4 +61,6 @@ public class SortServiceImpl implements GeneralComputingService {
    */
   protected native long[] nperformBubbleSort(ValueInfo[] valinfos);
 
+  protected native long[] nperform1DLongBubbleSort(ValueInfo[] valinfos);
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/0c0a20dc/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
index fc93968..ccb878d 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
@@ -28,7 +28,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/../dist/native")
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
 set(CMAKE_BUILD_TYPE "Release")
 set(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 -Wall -rdynamic -g -ggdb")
-set(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -O3 -Wall")
+set(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -march=native -O3 -Wall")
 
 find_package(JNI REQUIRED)
 include_directories(${JNI_INCLUDE_DIRS})

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/0c0a20dc/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.c
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.c
b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.c
index 40fda19..6f84c6c 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.c
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.c
@@ -135,3 +135,115 @@ jlongArray JNICALL Java_org_apache_mnemonic_service_computingservice_internal_So
   destructNValueInfos(nvinfos, visz);
   return ret;
 }
+
+#define TO_E(nvi, p) addr_from_java(p)
+
+typedef struct {
+  long scan_count;
+  long swap_count;
+  long noswap_count;
+} SortInfo;
+
+long handle1DLongBubbleSort(JNIEnv* env, struct NValueInfo *nvinfo, SortInfo *sortinfo) {
+  if (NULL == nvinfo->frames || 0 >= nvinfo->framessz) {
+    return 0L;
+  }
+  register long *itmaddrs = NULL;
+  register long *nxtfitmaddrs = NULL;
+  register int pendings = 0;
+  register long hdls = 0;
+  hdls = nvinfo->handler;
+  itmaddrs = &nvinfo->handler;
+  register long *iatmp;
+  register long curoff = nvinfo->frames->nextoff;
+  register long curnloff = nvinfo->frames->nlvloff;
+//  register long curnlsz = nvinfo->frames->nlvlsz;
+  register void *addr = NULL;
+  assert(-1L != curoff);
+  iatmp = itmaddrs;
+  register long *hptr1 = NULL, *hptr2 = NULL;
+  register void *pvaladdr = NULL;
+  register long *tmpptr = NULL;
+  register long tmpval = 0L;
+  register long cntscan = 0L, cntswap = 0L, cntnoswap = 0L;
+
+  if (0L == hdls) {
+    return 0L;
+  }
+
+  do {
+    ++cntscan;
+    pendings = 0;
+    pvaladdr = NULL;
+
+    addr = TO_E(nvinfo, hdls) + curnloff;
+    nxtfitmaddrs = (long*)(TO_E(nvinfo, hdls) + curoff);
+    pvaladdr = addr;
+    hptr2 = itmaddrs;
+
+    while (1) {
+      itmaddrs = nxtfitmaddrs;
+      hdls = *itmaddrs;
+      if (0L == hdls) {
+        break;
+      }
+      addr = TO_E(nvinfo, hdls) + curnloff;
+      nxtfitmaddrs = (long*)(TO_E(nvinfo, hdls) + curoff);
+
+      hptr1 = hptr2;
+      hptr2 = itmaddrs;
+      if (*(long*)pvaladdr > *(long*)addr) {
+        tmpptr = nxtfitmaddrs;
+        tmpval = *tmpptr;
+        *tmpptr = *hptr1;
+        *hptr1 = *hptr2;
+        *hptr2 = tmpval;
+        nxtfitmaddrs = hptr2;
+        hptr2 = tmpptr;
+        pendings = 1;
+        ++cntswap;
+      } else {
+        pvaladdr = addr;
+        ++cntnoswap;
+      }
+
+    }
+
+    itmaddrs = iatmp;
+    hdls = *iatmp;
+  } while (0 != pendings);
+
+  if (NULL != sortinfo) {
+    sortinfo->scan_count = cntscan;
+    sortinfo->swap_count = cntswap;
+    sortinfo->noswap_count = cntnoswap;
+  }
+  return nvinfo->handler;
+}
+
+JNIEXPORT
+jlongArray JNICALL Java_org_apache_mnemonic_service_computingservice_internal_SortServiceImpl_nperform1DLongBubbleSort(
+    JNIEnv* env, jobject this, jobjectArray vinfos) {
+  jlongArray ret = NULL;
+  jsize retsz = 1;
+  jsize idx;
+  size_t visz;
+  SortInfo sortinfo;
+  struct NValueInfo **nvinfos = constructNValueInfos(env, vinfos, &visz);
+  retsz = visz + 3;
+  jlong nret[retsz];
+  for(idx = 0; idx < retsz; ++idx) {
+    nret[idx] = 0L;
+  }
+  printNValueInfos(nvinfos, visz);
+  assert(1 == visz);
+
+  nret[0] = handle1DLongBubbleSort(env, *nvinfos, &sortinfo);
+  nret[1] = sortinfo.scan_count;
+  nret[2] = sortinfo.swap_count;
+  nret[3] = sortinfo.noswap_count;
+
+  ret = constructJLongArray(env, nret, retsz);
+  destructNValueInfos(nvinfos, visz);
+  return ret;
+}


Mime
View raw message