aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/clover/api/program.cpp
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2013-09-17 23:20:11 -0700
committerFrancisco Jerez <[email protected]>2013-10-21 10:47:03 -0700
commit35307f540fedf9680ce8b05d0784c5b0d5b0f6a7 (patch)
treeef065d58d8b6cc400abb09d2a523d6f6fded1d8b /src/gallium/state_trackers/clover/api/program.cpp
parent9968d9daf264b726ee50bbc97937daac4e9c1811 (diff)
clover: Switch kernel and program objects to the new model.
Tested-by: Tom Stellard <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/api/program.cpp')
-rw-r--r--src/gallium/state_trackers/clover/api/program.cpp117
1 files changed, 55 insertions, 62 deletions
diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp
index f6c12f40367..84260472953 100644
--- a/src/gallium/state_trackers/clover/api/program.cpp
+++ b/src/gallium/state_trackers/clover/api/program.cpp
@@ -28,7 +28,7 @@ using namespace clover;
PUBLIC cl_program
clCreateProgramWithSource(cl_context d_ctx, cl_uint count,
const char **strings, const size_t *lengths,
- cl_int *errcode_ret) try {
+ cl_int *r_errcode) try {
auto &ctx = obj(d_ctx);
std::string source;
@@ -43,19 +43,20 @@ clCreateProgramWithSource(cl_context d_ctx, cl_uint count,
std::string(strings[i]));
// ...and create a program object for them.
- ret_error(errcode_ret, CL_SUCCESS);
+ ret_error(r_errcode, CL_SUCCESS);
return new program(ctx, source);
} catch (error &e) {
- ret_error(errcode_ret, e);
+ ret_error(r_errcode, e);
return NULL;
}
PUBLIC cl_program
clCreateProgramWithBinary(cl_context d_ctx, cl_uint n,
- const cl_device_id *d_devs, const size_t *lengths,
- const unsigned char **binaries, cl_int *status_ret,
- cl_int *errcode_ret) try {
+ const cl_device_id *d_devs,
+ const size_t *lengths,
+ const unsigned char **binaries,
+ cl_int *r_status, cl_int *r_errcode) try {
auto &ctx = obj(d_ctx);
auto devs = objs(d_devs, n);
@@ -68,7 +69,7 @@ clCreateProgramWithBinary(cl_context d_ctx, cl_uint n,
throw error(CL_INVALID_DEVICE);
// Deserialize the provided binaries,
- auto modules = map(
+ auto result = map(
[](const unsigned char *p, size_t l) -> std::pair<cl_int, module> {
if (!p || !l)
return { CL_INVALID_VALUE, {} };
@@ -87,69 +88,64 @@ clCreateProgramWithBinary(cl_context d_ctx, cl_uint n,
range(lengths, n));
// update the status array,
- if (status_ret)
- copy(map(keys(), modules), status_ret);
+ if (r_status)
+ copy(map(keys(), result), r_status);
- if (any_of(key_equals(CL_INVALID_VALUE), modules))
+ if (any_of(key_equals(CL_INVALID_VALUE), result))
throw error(CL_INVALID_VALUE);
- if (any_of(key_equals(CL_INVALID_BINARY), modules))
+ if (any_of(key_equals(CL_INVALID_BINARY), result))
throw error(CL_INVALID_BINARY);
// initialize a program object with them.
- ret_error(errcode_ret, CL_SUCCESS);
- return new program(ctx, map(addresses(), devs), map(values(), modules));
+ ret_error(r_errcode, CL_SUCCESS);
+ return new program(ctx, devs, map(values(), result));
} catch (error &e) {
- ret_error(errcode_ret, e);
+ ret_error(r_errcode, e);
return NULL;
}
PUBLIC cl_int
-clRetainProgram(cl_program prog) {
- if (!prog)
- return CL_INVALID_PROGRAM;
-
- prog->retain();
+clRetainProgram(cl_program d_prog) try {
+ obj(d_prog).retain();
return CL_SUCCESS;
+
+} catch (error &e) {
+ return e.get();
}
PUBLIC cl_int
-clReleaseProgram(cl_program prog) {
- if (!prog)
- return CL_INVALID_PROGRAM;
-
- if (prog->release())
- delete prog;
+clReleaseProgram(cl_program d_prog) try {
+ if (obj(d_prog).release())
+ delete pobj(d_prog);
return CL_SUCCESS;
+
+} catch (error &e) {
+ return e.get();
}
PUBLIC cl_int
-clBuildProgram(cl_program prog, cl_uint count, const cl_device_id *devs,
- const char *opts, void (*pfn_notify)(cl_program, void *),
+clBuildProgram(cl_program d_prog, cl_uint num_devs,
+ const cl_device_id *d_devs, const char *p_opts,
+ void (*pfn_notify)(cl_program, void *),
void *user_data) try {
- if (!prog)
- throw error(CL_INVALID_PROGRAM);
+ auto &prog = obj(d_prog);
+ auto devs = (d_devs ? objs(d_devs, num_devs) :
+ ref_vector<device>(map(derefs(), prog.ctx.devs)));
+ auto opts = (p_opts ? p_opts : "");
- if (bool(count) != bool(devs) ||
+ if (bool(num_devs) != bool(d_devs) ||
(!pfn_notify && user_data))
throw error(CL_INVALID_VALUE);
- if (!opts)
- opts = "";
-
- if (devs) {
- if (any_of([&](const cl_device_id dev) {
- return !prog->ctx.has_device(obj(dev));
- }, range(devs, count)))
- throw error(CL_INVALID_DEVICE);
-
- prog->build(map(addresses(), objs(devs, count)), opts);
- } else {
- prog->build(prog->ctx.devs, opts);
- }
+ if (any_of([&](device &dev) {
+ return !prog.ctx.has_device(dev);
+ }, devs))
+ throw error(CL_INVALID_DEVICE);
+ prog.build(devs, opts);
return CL_SUCCESS;
} catch (error &e) {
@@ -162,32 +158,30 @@ clUnloadCompiler() {
}
PUBLIC cl_int
-clGetProgramInfo(cl_program prog, cl_program_info param,
+clGetProgramInfo(cl_program d_prog, cl_program_info param,
size_t size, void *r_buf, size_t *r_size) try {
property_buffer buf { r_buf, size, r_size };
-
- if (!prog)
- return CL_INVALID_PROGRAM;
+ auto &prog = obj(d_prog);
switch (param) {
case CL_PROGRAM_REFERENCE_COUNT:
- buf.as_scalar<cl_uint>() = prog->ref_count();
+ buf.as_scalar<cl_uint>() = prog.ref_count();
break;
case CL_PROGRAM_CONTEXT:
- buf.as_scalar<cl_context>() = &prog->ctx;
+ buf.as_scalar<cl_context>() = desc(prog.ctx);
break;
case CL_PROGRAM_NUM_DEVICES:
- buf.as_scalar<cl_uint>() = prog->binaries().size();
+ buf.as_scalar<cl_uint>() = prog.binaries().size();
break;
case CL_PROGRAM_DEVICES:
- buf.as_vector<cl_device_id>() = map(keys(), prog->binaries());
+ buf.as_vector<cl_device_id>() = map(keys(), prog.binaries());
break;
case CL_PROGRAM_SOURCE:
- buf.as_string() = prog->source();
+ buf.as_string() = prog.source();
break;
case CL_PROGRAM_BINARY_SIZES:
@@ -198,7 +192,7 @@ clGetProgramInfo(cl_program prog, cl_program_info param,
ent.second.serialize(s);
return bin.size();
},
- prog->binaries());
+ prog.binaries());
break;
case CL_PROGRAM_BINARIES:
@@ -209,7 +203,7 @@ clGetProgramInfo(cl_program prog, cl_program_info param,
ent.second.serialize(s);
return bin;
},
- prog->binaries());
+ prog.binaries());
break;
default:
@@ -223,28 +217,27 @@ clGetProgramInfo(cl_program prog, cl_program_info param,
}
PUBLIC cl_int
-clGetProgramBuildInfo(cl_program prog, cl_device_id dev,
+clGetProgramBuildInfo(cl_program d_prog, cl_device_id d_dev,
cl_program_build_info param,
size_t size, void *r_buf, size_t *r_size) try {
property_buffer buf { r_buf, size, r_size };
+ auto &prog = obj(d_prog);
+ auto &dev = obj(d_dev);
- if (!prog)
- return CL_INVALID_PROGRAM;
-
- if (!prog->ctx.has_device(obj(dev)))
+ if (!prog.ctx.has_device(dev))
return CL_INVALID_DEVICE;
switch (param) {
case CL_PROGRAM_BUILD_STATUS:
- buf.as_scalar<cl_build_status>() = prog->build_status(pobj(dev));
+ buf.as_scalar<cl_build_status>() = prog.build_status(dev);
break;
case CL_PROGRAM_BUILD_OPTIONS:
- buf.as_string() = prog->build_opts(pobj(dev));
+ buf.as_string() = prog.build_opts(dev);
break;
case CL_PROGRAM_BUILD_LOG:
- buf.as_string() = prog->build_log(pobj(dev));
+ buf.as_string() = prog.build_log(dev);
break;
default: