diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2012-12-11 04:03:29 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2012-12-11 04:03:29 +0000 |
commit | 86b1de85536e93c59a25702a5a2d3e384202ffd2 (patch) | |
tree | c61d91970980199c597304ddcb01919993fbeb82 /sca-cpp/trunk/modules/opencl | |
parent | 5f29c3b769fcdb2532d4948aa1c649d4330304b9 (diff) |
More changes to port to C++11, adjust to use the new JSON support, and cleanup rest of the modules.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1419987 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/modules/opencl/Makefile.am | 4 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/opencl/driver.hpp | 2 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/opencl/eval.hpp | 49 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/opencl/opencl-shell.cpp | 4 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/opencl/opencl-test.cpp | 72 |
5 files changed, 65 insertions, 66 deletions
diff --git a/sca-cpp/trunk/modules/opencl/Makefile.am b/sca-cpp/trunk/modules/opencl/Makefile.am index 3e76a435c8..92da55b307 100644 --- a/sca-cpp/trunk/modules/opencl/Makefile.am +++ b/sca-cpp/trunk/modules/opencl/Makefile.am @@ -36,7 +36,7 @@ endif #mod_LTLIBRARIES = libmod_tuscany_opencl.la #libmod_tuscany_opencl_la_SOURCES = mod-opencl.cpp -#libmod_tuscany_opencl_la_LDFLAGS = -lxml2 -lcurl -lmozjs -framework OpenCL +#libmod_tuscany_opencl_la_LDFLAGS = -lxml2 -lcurl -ljansson -framework OpenCL #noinst_DATA = libmod_tuscany_opencl${libsuffix} #libmod_tuscany_opencl${libsuffix}: # ln -s .libs/libmod_tuscany_opencl${libsuffix} @@ -48,7 +48,7 @@ opencl_shell_SOURCES = opencl-shell.cpp opencl_shell_LDFLAGS = ${OPENCL_FLAGS} client_test_SOURCES = client-test.cpp -client_test_LDFLAGS = -lxml2 -lcurl -lmozjs +client_test_LDFLAGS = -lxml2 -lcurl -ljansson dist_noinst_SCRIPTS = server-test noinst_PROGRAMS = opencl-test client-test diff --git a/sca-cpp/trunk/modules/opencl/driver.hpp b/sca-cpp/trunk/modules/opencl/driver.hpp index b4b6c2845b..c45bcf6ee4 100644 --- a/sca-cpp/trunk/modules/opencl/driver.hpp +++ b/sca-cpp/trunk/modules/opencl/driver.hpp @@ -37,7 +37,7 @@ namespace opencl { const value evalDriverLoop(const OpenCLProgram& clprog, istream& in, ostream& out, const OpenCLContext& cl) { scheme::promptForInput(scheme::evalInputPrompt, out); - value input = scheme::readValue(in); + const value input = content(scheme::readValue(in)); if (isNil(input)) return input; const failable<value> output = evalKernel(createKernel(input, clprog), input, 1, value::String, 512, cl); diff --git a/sca-cpp/trunk/modules/opencl/eval.hpp b/sca-cpp/trunk/modules/opencl/eval.hpp index 5606b2f57a..f842ba783d 100644 --- a/sca-cpp/trunk/modules/opencl/eval.hpp +++ b/sca-cpp/trunk/modules/opencl/eval.hpp @@ -61,7 +61,7 @@ cl_ulong evaltime = 0; /** * Reset the OpenCL profiling counters. */ -bool resetOpenCLCounters() { +const bool resetOpenCLCounters() { memtime = kernelqtime = kerneltime = preptime = evaltime = 0; return true; } @@ -69,7 +69,7 @@ bool resetOpenCLCounters() { /** * Print the OpenCL profiling counters. */ -bool printOpenCLCounters(const long n) { +const bool printOpenCLCounters(const long n) { cout << " kernelq " << ((double)kernelqtime / 1000000.0) / (double)n << " ms kernel " << ((double)kerneltime / 1000000.0) / (double)n << " ms memory " << ((double)memtime / 1000000.0) / (double)n << " ms prep " << ((double)preptime / 1000000.0) / (double)n << " ms eval " << ((double)evaltime / 1000000.0) / (double)n << " ms"; return true; } @@ -77,7 +77,7 @@ bool printOpenCLCounters(const long n) { /** * Profile a memory event. */ -failable<cl_ulong> profileMemEvent(const cl_event evt) { +const failable<cl_ulong> profileMemEvent(const cl_event evt) { cl_ulong start = 0; const cl_int serr = clGetEventProfilingInfo(evt, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &start, NULL); if (serr != CL_SUCCESS) @@ -94,7 +94,7 @@ failable<cl_ulong> profileMemEvent(const cl_event evt) { /** * Profile a kernel event. */ -failable<cl_ulong> profileKernelEvent(const cl_event evt) { +const failable<cl_ulong> profileKernelEvent(const cl_event evt) { cl_ulong queued = 0; const cl_int qerr = clGetEventProfilingInfo(evt, CL_PROFILING_COMMAND_QUEUED, sizeof(cl_ulong), &queued, NULL); if (qerr != CL_SUCCESS) @@ -117,7 +117,7 @@ failable<cl_ulong> profileKernelEvent(const cl_event evt) { /** * Profile an array of memory events. */ -failable<cl_ulong> profileMemEvents(const cl_uint n, const cl_event* evt) { +const failable<cl_ulong> profileMemEvents(const cl_uint n, const cl_event* const evt) { if (n == 0) return 0; const failable<cl_ulong> t = profileMemEvent(*evt); @@ -221,6 +221,21 @@ public: } } + OpenCLContext(const OpenCLContext& c) : dev(c.dev), ndevs(c.ndevs), ctx(c.ctx) { + for (cl_uint i = 0; i < ndevs; i++) { + devid[i] = c.devid[i]; + cq[i] = c.cq[i]; + if (cq[i] != 0) { + const cl_int rcqerr = clRetainCommandQueue(cq[i]); + if (rcqerr != CL_SUCCESS) + mkfailure<bool>(string("Couldn't retain OpenCL command queue: ") + clError(rcqerr)); + } + } + const cl_int rcerr = clRetainContext(ctx); + if (rcerr != CL_SUCCESS) + mkfailure<bool>(string("Couldn't retain OpenCL context: ") + clError(rcerr)); + } + ~OpenCLContext() { for (cl_uint i = 0; i < ndevs; i++) { if (cq[i] != 0) @@ -372,7 +387,7 @@ private: /** * Return a read-only memory buffer. */ -const failable<OpenCLBuffer> readOnlyBuffer(const size_t size, const void* p, const OpenCLContext& cl, const cl_command_queue cq) { +const failable<OpenCLBuffer> readOnlyBuffer(const size_t size, const void* const p, const OpenCLContext& cl, const cl_command_queue cq) { if (cl.dev == OpenCLContext::CPU) { cl_int err; const cl_mem buf = clCreateBuffer(cl.ctx, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, size, const_cast<void*>(p), &err); @@ -396,7 +411,7 @@ const failable<OpenCLBuffer> readOnlyBuffer(const size_t size, const void* p, co /** * Fill an array of write events for a given list of buffers. */ -const cl_uint writeBufferEvents(const list<OpenCLBuffer>& buf, cl_event* evt) { +const cl_uint writeBufferEvents(const list<OpenCLBuffer>& buf, cl_event* const evt) { if (isNil(buf)) return 0; const cl_event e = car(buf).evt; @@ -427,7 +442,7 @@ const failable<OpenCLBuffer> writeOnlyBuffer(const size_t size, const OpenCLCont /** * Convert a value to a kernel arg. */ -const failable<OpenCLBuffer> valueToKernelArg(const cl_uint i, const size_t size, const void* p, const failable<OpenCLBuffer>& buf, const OpenCLKernel& kernel) { +const failable<OpenCLBuffer> valueToKernelArg(const cl_uint i, const size_t size, const void* const p, const failable<OpenCLBuffer>& buf, const OpenCLKernel& kernel) { if (!hasContent(buf)) return buf; if (p != NULL) { @@ -446,7 +461,7 @@ const failable<OpenCLBuffer> valueToKernelArg(const cl_uint i, const size_t size const failable<OpenCLBuffer> valueToKernelArg(const value& v, const cl_uint i, const OpenCLKernel& kernel, const OpenCLContext& cl, const cl_command_queue cq) { switch (type(v)) { case value::Symbol: { - const string s = string("'") + v; + const string s = string("'") + (string)v; return valueToKernelArg(i, 0, NULL, readOnlyBuffer(length(s) + 1, c_str(s), cl, cq), kernel); } case value::String: { @@ -489,28 +504,28 @@ const failable<list<OpenCLBuffer>> valuesToKernelArgs(const list<value>& v, cons /** * Convert a kernel result to a value. */ -const value kernelResultToValue(const void* p, const value::ValueType type) { +const value kernelResultToValue(const void* const p, const value::ValueType type) { switch(type) { case value::Symbol: { - const char* s = static_cast<const char*>(p); + const char* const s = (const char*)p; const size_t l = strlen(s); if (l != 0 && *s == '\'') return value(s + 1); return value(s); } case value::String: { - const char* s = static_cast<const char*>(p); + const char* const s = (const char*)p; const size_t l = strlen(s); if (l != 0 && *s == '\'') return value(s + 1); return value(string(s, l)); } case value::Number: - return (double)(*(static_cast<const cl_float*>(p))); + return (double)(*(const cl_float*)p); case value::Bool: - return (bool)(*(static_cast<const cl_int*>(p))); + return (bool)(*(const cl_int*)p); default: - return *(static_cast<const value*>(p)); + return *(const value*)p; } } @@ -582,9 +597,9 @@ const failable<OpenCLKernel> createKernel(const value& expr, const OpenCLProgram // The start, stop, and restart functions are optional //if (fn == "start" || fn == "stop") - //return value(lambda<value(const list<value>&)>()); + //return value(lvvlambda()); - return mkfailure<OpenCLKernel>(string("Couldn't find function: ") + car<value>(expr) + " : " + clError(ckerr)); + return mkfailure<OpenCLKernel>(string("Couldn't find function: ") + (string)car<value>(expr) + " : " + clError(ckerr)); } return OpenCLKernel(k); } diff --git a/sca-cpp/trunk/modules/opencl/opencl-shell.cpp b/sca-cpp/trunk/modules/opencl/opencl-shell.cpp index 1dfeaeea1d..a0598c9d32 100644 --- a/sca-cpp/trunk/modules/opencl/opencl-shell.cpp +++ b/sca-cpp/trunk/modules/opencl/opencl-shell.cpp @@ -29,8 +29,8 @@ #include "string.hpp" #include "driver.hpp" -int main(const int argc, char** argv) { - tuscany::gc_scoped_pool pool; +int main(const int argc, char** const argv) { + const tuscany::gc_scoped_pool pool; if (argc != 2) { tuscany::cerr << "Usage: opencl-shell <kernel.cl>" << tuscany::endl; return 1; diff --git a/sca-cpp/trunk/modules/opencl/opencl-test.cpp b/sca-cpp/trunk/modules/opencl/opencl-test.cpp index 17bc5ccfa6..4c7f3fa86b 100644 --- a/sca-cpp/trunk/modules/opencl/opencl-test.cpp +++ b/sca-cpp/trunk/modules/opencl/opencl-test.cpp @@ -159,8 +159,8 @@ const string testCharsParallelGPU = " r[i] = i < ixl? x[i] : i < ixl + iyl? y[i - ixl] : '\\0';\n" "}\n"; -bool testTaskParallel(const OpenCLContext::DeviceType dev) { - gc_scoped_pool pool; +const bool testTaskParallel(const OpenCLContext::DeviceType dev) { + const gc_scoped_pool pool; OpenCLContext cl(dev); if (!devices(cl) != 0) return true; @@ -192,12 +192,12 @@ bool testTaskParallel(const OpenCLContext::DeviceType dev) { const value exp = mklist<value>("int_or", true, false); const failable<value> r = evalKernel(createKernel(exp, content(clprog)), exp, cl); assert(hasContent(r)); - assert(content(r) == value(true)); + assert(content(r) == trueValue); const value exp2 = mklist<value>("int_or", false, false); const failable<value> r2 = evalKernel(createKernel(exp2, content(clprog)), exp2, cl); assert(hasContent(r2)); - assert(content(r2) == value(false)); + assert(content(r2) == falseValue); } { istringstream is(dev == OpenCLContext::CPU? testCharsCPU : testCharsGPU); @@ -223,41 +223,33 @@ bool testTaskParallel(const OpenCLContext::DeviceType dev) { return true; } -struct evalTaskParallelLoop { - evalTaskParallelLoop(const OpenCLContext& cl, const OpenCLProgram& clprog) : cl(cl), clprog(clprog), exp(mklist<value>("add", 60, string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello "), 60, string("World World World World World World World World World World "))) { - } - const bool operator()() const { - const failable<value> r = evalKernel(createKernel(exp, clprog), exp, 1, value::String, 128, cl); - assert(hasContent(r)); - assert(content(r) == value(string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello World World World World World World World World World World "))); - return true; - } - - const OpenCLContext& cl; - const OpenCLProgram& clprog; - const value exp; -}; - const bool testTaskParallelPerf(const OpenCLContext::DeviceType dev, const bool copy) { - gc_scoped_pool pool; + const gc_scoped_pool pool; OpenCLContext cl(dev); if (!devices(cl) != 0) return true; istringstream is(dev == OpenCLContext::CPU? testCharsCPU : copy? testCharsCopyGPU : testCharsGPU); - failable<OpenCLProgram> clprog = readProgram("kernel.cl", is, cl); - assert(hasContent(clprog)); + failable<OpenCLProgram> fclprog = readProgram("kernel.cl", is, cl); + assert(hasContent(fclprog)); resetOpenCLCounters(); - const lambda<bool()> el = evalTaskParallelLoop(cl, content(clprog)); + OpenCLProgram clprog = content(fclprog); + const value exp = mklist<value>("add", 60, string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello "), 60, string("World World World World World World World World World World ")); + const blambda el = [cl, clprog, exp]() -> const bool { + const failable<value> r = evalKernel(createKernel(exp, clprog), exp, 1, value::String, 128, cl); + assert(hasContent(r)); + assert(content(r) == value(string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello World World World World World World World World World World "))); + return true; + }; cout << "OpenCL task-parallel eval " << (dev == OpenCLContext::CPU? "CPU" : "GPU") << (copy? " copy" : "") << " test " << time(el, 5, 500) << " ms"; printOpenCLCounters(500); cout << endl; return true; } -bool testDataParallel(const OpenCLContext::DeviceType dev) { - gc_scoped_pool pool; +const bool testDataParallel(const OpenCLContext::DeviceType dev) { + const gc_scoped_pool pool; OpenCLContext cl(dev); if (!devices(cl) != 0) return true; @@ -276,33 +268,25 @@ bool testDataParallel(const OpenCLContext::DeviceType dev) { return true; } -struct evalDataParallelLoop { - evalDataParallelLoop(const OpenCLContext& cl, const OpenCLProgram& clprog) : cl(cl), clprog(clprog), exp(mklist<value>("add", 60, string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello "), 60, string("World World World World World World World World World World "))) { - } - const bool operator()() const { - const failable<value> r = evalKernel(createKernel(exp, clprog), exp, 121, value::String, 128, cl); - assert(hasContent(r)); - assert(content(r) == value(string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello World World World World World World World World World World "))); - return true; - } - - const OpenCLContext& cl; - const OpenCLProgram& clprog; - const value exp; -}; - const bool testDataParallelPerf(const OpenCLContext::DeviceType dev, const bool copy) { - gc_scoped_pool pool; + const gc_scoped_pool pool; OpenCLContext cl(dev); if (!devices(cl) != 0) return true; istringstream is(dev == OpenCLContext::CPU? testCharsParallelCPU : copy? testCharsParallelCopyGPU : testCharsParallelGPU); - failable<OpenCLProgram> clprog = readProgram("kernel.cl", is, cl); - assert(hasContent(clprog)); + failable<OpenCLProgram> fclprog = readProgram("kernel.cl", is, cl); + assert(hasContent(fclprog)); resetOpenCLCounters(); - const lambda<bool()> el = evalDataParallelLoop(cl, content(clprog)); + OpenCLProgram clprog = content(fclprog); + const value exp = mklist<value>("add", 60, string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello "), 60, string("World World World World World World World World World World ")); + const blambda el = [cl, clprog, exp]() -> const bool { + const failable<value> r = evalKernel(createKernel(exp, clprog), exp, 121, value::String, 128, cl); + assert(hasContent(r)); + assert(content(r) == value(string("Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello World World World World World World World World World World "))); + return true; + }; cout << "OpenCL data-parallel eval " << (dev == OpenCLContext::CPU? "CPU" : "GPU") << (copy? " copy" : "") << " test " << time(el, 5, 500) << " ms"; printOpenCLCounters(500); cout << endl; |