Add hello example for basic Kokkos interoperability 35/4735/3
authorJaemin Choi <jchoi157@illinois.edu>
Fri, 26 Oct 2018 03:34:31 +0000 (23:34 -0400)
committerJaemin Choi <jchoi157@illinois.edu>
Wed, 16 Jan 2019 22:18:26 +0000 (16:18 -0600)
Change-Id: I6d1b99178bde1da819ab36be3d5b81a0eda2b703

examples/charm++/kokkos/hello-dist/Makefile [new file with mode: 0644]
examples/charm++/kokkos/hello-dist/README [new file with mode: 0644]
examples/charm++/kokkos/hello-dist/hello.C [new file with mode: 0644]
examples/charm++/kokkos/hello-dist/hello.ci [new file with mode: 0644]
examples/charm++/kokkos/hello/Makefile [new file with mode: 0644]
examples/charm++/kokkos/hello/README [new file with mode: 0644]
examples/charm++/kokkos/hello/hello.C [new file with mode: 0644]
examples/charm++/kokkos/hello/hello.ci [new file with mode: 0644]

diff --git a/examples/charm++/kokkos/hello-dist/Makefile b/examples/charm++/kokkos/hello-dist/Makefile
new file mode 100644 (file)
index 0000000..2d9e7c5
--- /dev/null
@@ -0,0 +1,26 @@
+-include ../../../common.mk
+CHARMC = ../../../../bin/charmc $(OPTS)
+
+# Paths need to be set for include and lib folders of Kokkos
+# KOKKOS_INC and KOKKOS_LIB respectively
+KOKKOS_INC ?= /home/jchoi157/kokkos/build/include
+KOKKOS_LIB ?= /home/jchoi157/kokkos/build/lib
+
+OBJS = hello.o
+
+all: hello
+
+hello: $(OBJS)
+       $(CHARMC) -language charm++ -L$(KOKKOS_LIB) -lkokkos -lpthread -o hello $(OBJS)
+
+hello.decl.h: hello.ci
+       $(CHARMC) hello.ci
+
+clean:
+       rm -f *.decl.h *.def.h *.o hello charmrun
+
+hello.o: hello.C hello.decl.h
+       $(CHARMC) -I$(KOKKOS_INC) -c hello.C
+
+test: all
+       $(call run, ./hello +p2 ++local)
diff --git a/examples/charm++/kokkos/hello-dist/README b/examples/charm++/kokkos/hello-dist/README
new file mode 100644 (file)
index 0000000..c5b287f
--- /dev/null
@@ -0,0 +1,7 @@
+Hello World with Kokkos (Distributed)
+
+Demonstrates basic interoperability with Kokkos.
+Paths to include and lib folders of Kokkos (KOKKOS_INC and KOKKOS_LIB, respecitvely)
+need to be set as environment variables or provided to the Makefile.
+Uses nodegroup to allow a separate instance of Kokkos to run on each process.
+The tricky part is getting argc and argv fed correctly to Kokkos::initialize().
diff --git a/examples/charm++/kokkos/hello-dist/hello.C b/examples/charm++/kokkos/hello-dist/hello.C
new file mode 100644 (file)
index 0000000..b28910f
--- /dev/null
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include "hello.decl.h"
+#include "pup_stl.h"
+#include <vector>
+#include <string>
+
+#include <Kokkos_Core.hpp>
+#include <typeinfo>
+
+/* readonly */ CProxy_Main mainProxy;
+/* readonly */ CProxy_Hello helloProxy;
+
+class Main : public CBase_Main {
+public:
+  Main(CkArgMsg* m) {
+    // Pack arguments
+    std::vector<std::string> args;
+    for (int i = 0; i < m->argc; i++) {
+      args.push_back(std::string(m->argv[i]));
+    }
+
+    // Create nodegroup and run
+    helloProxy = CProxy_Hello::ckNew(m->argc, args);
+    helloProxy.run();
+  };
+
+  void done() {
+    CkPrintf("All done\n");
+
+    CkExit();
+  };
+};
+
+class Hello : public CBase_Hello {
+public:
+  Hello(int argc, std::vector<std::string> args) {
+    char* argv[argc];
+    for (int i = 0; i < argc; i++) {
+      argv[i] = const_cast<char*>(args[i].c_str());
+    }
+
+    // Initialize Kokkos. Needs to be done on every process
+    Kokkos::initialize(argc, argv);
+  }
+
+  void run() {
+    CkPrintf("Hello World on Kokkos execution space %s\n",
+             typeid(Kokkos::DefaultExecutionSpace).name());
+
+    // Parallel execution with Kokkos
+#if defined(KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA)
+    Kokkos::parallel_for(16, KOKKOS_LAMBDA (const int i) {
+      printf("Hello from i = %i\n", i);
+    });
+#endif
+
+    // Finialize Kokkos. Needs to be done on every process
+    Kokkos::finalize();
+
+    // Reduce to Main to end the program
+    CkCallback cb(CkReductionTarget(Main, done), mainProxy);
+    contribute(cb);
+  }
+};
+
+#include "hello.def.h"
diff --git a/examples/charm++/kokkos/hello-dist/hello.ci b/examples/charm++/kokkos/hello-dist/hello.ci
new file mode 100644 (file)
index 0000000..58652ad
--- /dev/null
@@ -0,0 +1,14 @@
+mainmodule hello {
+  readonly CProxy_Main mainProxy;
+  readonly CProxy_Hello helloProxy;
+
+  mainchare Main {
+    entry Main(CkArgMsg *m);
+    entry [reductiontarget] void done();
+  };
+
+  nodegroup Hello {
+    entry Hello(int argc, std::vector<std::string> args);
+    entry void run();
+  };
+};
diff --git a/examples/charm++/kokkos/hello/Makefile b/examples/charm++/kokkos/hello/Makefile
new file mode 100644 (file)
index 0000000..12eb2e7
--- /dev/null
@@ -0,0 +1,26 @@
+-include ../../../common.mk
+CHARMC = ../../../../bin/charmc $(OPTS)
+
+# Paths need to be set for include and lib folders of Kokkos
+# KOKKOS_INC and KOKKOS_LIB respectively
+KOKKOS_INC ?= /home/jchoi157/kokkos/build/include
+KOKKOS_LIB ?= /home/jchoi157/kokkos/build/lib
+
+OBJS = hello.o
+
+all: hello
+
+hello: $(OBJS)
+       $(CHARMC) -language charm++ -L$(KOKKOS_LIB) -lkokkos -lpthread -o hello $(OBJS)
+
+hello.decl.h: hello.ci
+       $(CHARMC) hello.ci
+
+clean:
+       rm -f *.decl.h *.def.h *.o hello charmrun
+
+hello.o: hello.C hello.decl.h
+       $(CHARMC) -I$(KOKKOS_INC) -c hello.C
+
+test: all
+       $(call run, ./hello)
diff --git a/examples/charm++/kokkos/hello/README b/examples/charm++/kokkos/hello/README
new file mode 100644 (file)
index 0000000..c3334dd
--- /dev/null
@@ -0,0 +1,5 @@
+Hello World with Kokkos
+
+Demonstrates basic interoperability with Kokkos.
+Paths to include and lib folders of Kokkos (KOKKOS_INC and KOKKOS_LIB, respecitvely)
+need to be set as environment variables or provided to the Makefile.
diff --git a/examples/charm++/kokkos/hello/hello.C b/examples/charm++/kokkos/hello/hello.C
new file mode 100644 (file)
index 0000000..6f18eef
--- /dev/null
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include "hello.decl.h"
+#include <Kokkos_Core.hpp>
+#include <typeinfo>
+
+/* readonly */ CProxy_Main mainProxy;
+
+class Main : public CBase_Main {
+public:
+  Main(CkArgMsg* m) {
+    // Initialize Kokkos
+    Kokkos::initialize(m->argc, m->argv);
+
+    CkPrintf("Hello World on Kokkos execution space %s\n",
+             typeid(Kokkos::DefaultExecutionSpace).name());
+
+    // Parallel execution with Kokkos
+#if defined(KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA)
+    Kokkos::parallel_for(16, KOKKOS_LAMBDA (const int i) {
+      printf("Hello from i = %i\n", i);
+    });
+#endif
+
+    done();
+  };
+
+  void done()
+  {
+    CkPrintf("All done\n");
+
+    // Finalize Kokkos and exit
+    Kokkos::finalize();
+    CkExit();
+  };
+};
+
+#include "hello.def.h"
diff --git a/examples/charm++/kokkos/hello/hello.ci b/examples/charm++/kokkos/hello/hello.ci
new file mode 100644 (file)
index 0000000..ec57df1
--- /dev/null
@@ -0,0 +1,8 @@
+mainmodule hello {
+  readonly CProxy_Main mainProxy;
+
+  mainchare Main {
+    entry Main(CkArgMsg *m);
+    entry void done();
+  };
+};