2012-04-20 16:56:19 +02:00
|
|
|
//
|
|
|
|
|
// Copyright 2012 Francisco Jerez
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
2013-04-21 13:52:08 -07:00
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
|
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
2012-04-20 16:56:19 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "api/util.hpp"
|
|
|
|
|
#include "core/program.hpp"
|
|
|
|
|
|
2015-04-23 20:13:51 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
|
2012-04-20 16:56:19 +02:00
|
|
|
using namespace clover;
|
|
|
|
|
|
2014-10-21 10:31:56 -04:00
|
|
|
namespace {
|
2016-05-17 16:03:18 +02:00
|
|
|
void
|
|
|
|
|
validate_build_common(const program &prog, cl_uint num_devs,
|
|
|
|
|
const cl_device_id *d_devs,
|
|
|
|
|
void (*pfn_notify)(cl_program, void *),
|
|
|
|
|
void *user_data) {
|
|
|
|
|
if (!pfn_notify && user_data)
|
2014-10-21 10:31:56 -04:00
|
|
|
throw error(CL_INVALID_VALUE);
|
|
|
|
|
|
|
|
|
|
if (prog.kernel_ref_count())
|
|
|
|
|
throw error(CL_INVALID_OPERATION);
|
|
|
|
|
|
|
|
|
|
if (any_of([&](const device &dev) {
|
|
|
|
|
return !count(dev, prog.context().devices());
|
2014-11-03 09:14:01 -05:00
|
|
|
}, objs<allow_empty_tag>(d_devs, num_devs)))
|
2014-10-21 10:31:56 -04:00
|
|
|
throw error(CL_INVALID_DEVICE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-06 13:52:02 -07:00
|
|
|
CLOVER_API cl_program
|
2013-09-15 20:50:30 -07:00
|
|
|
clCreateProgramWithSource(cl_context d_ctx, cl_uint count,
|
2012-04-20 16:56:19 +02:00
|
|
|
const char **strings, const size_t *lengths,
|
2013-09-17 23:20:11 -07:00
|
|
|
cl_int *r_errcode) try {
|
2013-09-15 20:50:30 -07:00
|
|
|
auto &ctx = obj(d_ctx);
|
2012-04-20 16:56:19 +02:00
|
|
|
std::string source;
|
|
|
|
|
|
|
|
|
|
if (!count || !strings ||
|
2013-10-06 13:49:05 -07:00
|
|
|
any_of(is_zero(), range(strings, count)))
|
2012-04-20 16:56:19 +02:00
|
|
|
throw error(CL_INVALID_VALUE);
|
|
|
|
|
|
|
|
|
|
// Concatenate all the provided fragments together
|
|
|
|
|
for (unsigned i = 0; i < count; ++i)
|
|
|
|
|
source += (lengths && lengths[i] ?
|
|
|
|
|
std::string(strings[i], strings[i] + lengths[i]) :
|
|
|
|
|
std::string(strings[i]));
|
|
|
|
|
|
|
|
|
|
// ...and create a program object for them.
|
2013-09-17 23:20:11 -07:00
|
|
|
ret_error(r_errcode, CL_SUCCESS);
|
2013-09-15 20:50:30 -07:00
|
|
|
return new program(ctx, source);
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
} catch (error &e) {
|
2013-09-17 23:20:11 -07:00
|
|
|
ret_error(r_errcode, e);
|
2012-04-20 16:56:19 +02:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-06 13:52:02 -07:00
|
|
|
CLOVER_API cl_program
|
2013-09-15 20:50:30 -07:00
|
|
|
clCreateProgramWithBinary(cl_context d_ctx, cl_uint n,
|
2013-09-17 23:20:11 -07:00
|
|
|
const cl_device_id *d_devs,
|
|
|
|
|
const size_t *lengths,
|
|
|
|
|
const unsigned char **binaries,
|
|
|
|
|
cl_int *r_status, cl_int *r_errcode) try {
|
2013-09-15 20:50:30 -07:00
|
|
|
auto &ctx = obj(d_ctx);
|
2013-09-15 20:06:57 -07:00
|
|
|
auto devs = objs(d_devs, n);
|
|
|
|
|
|
|
|
|
|
if (!lengths || !binaries)
|
2012-04-20 16:56:19 +02:00
|
|
|
throw error(CL_INVALID_VALUE);
|
|
|
|
|
|
2013-09-16 21:38:32 -07:00
|
|
|
if (any_of([&](const device &dev) {
|
2014-02-18 13:12:52 +01:00
|
|
|
return !count(dev, ctx.devices());
|
2013-09-15 20:06:57 -07:00
|
|
|
}, devs))
|
2012-04-20 16:56:19 +02:00
|
|
|
throw error(CL_INVALID_DEVICE);
|
|
|
|
|
|
|
|
|
|
// Deserialize the provided binaries,
|
2014-01-14 21:47:46 +01:00
|
|
|
std::vector<std::pair<cl_int, module>> result = map(
|
2012-04-20 16:56:19 +02:00
|
|
|
[](const unsigned char *p, size_t l) -> std::pair<cl_int, module> {
|
|
|
|
|
if (!p || !l)
|
|
|
|
|
return { CL_INVALID_VALUE, {} };
|
|
|
|
|
|
|
|
|
|
try {
|
2015-04-23 20:13:51 +02:00
|
|
|
std::stringbuf bin( { (char*)p, l } );
|
|
|
|
|
std::istream s(&bin);
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
return { CL_SUCCESS, module::deserialize(s) };
|
|
|
|
|
|
2015-04-23 20:13:51 +02:00
|
|
|
} catch (std::istream::failure &e) {
|
2012-04-20 16:56:19 +02:00
|
|
|
return { CL_INVALID_BINARY, {} };
|
|
|
|
|
}
|
|
|
|
|
},
|
2013-09-15 20:06:57 -07:00
|
|
|
range(binaries, n),
|
|
|
|
|
range(lengths, n));
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
// update the status array,
|
2013-09-17 23:20:11 -07:00
|
|
|
if (r_status)
|
|
|
|
|
copy(map(keys(), result), r_status);
|
2012-04-20 16:56:19 +02:00
|
|
|
|
2013-09-17 23:20:11 -07:00
|
|
|
if (any_of(key_equals(CL_INVALID_VALUE), result))
|
2012-04-20 16:56:19 +02:00
|
|
|
throw error(CL_INVALID_VALUE);
|
|
|
|
|
|
2013-09-17 23:20:11 -07:00
|
|
|
if (any_of(key_equals(CL_INVALID_BINARY), result))
|
2012-04-20 16:56:19 +02:00
|
|
|
throw error(CL_INVALID_BINARY);
|
|
|
|
|
|
|
|
|
|
// initialize a program object with them.
|
2013-09-17 23:20:11 -07:00
|
|
|
ret_error(r_errcode, CL_SUCCESS);
|
|
|
|
|
return new program(ctx, devs, map(values(), result));
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
} catch (error &e) {
|
2013-09-17 23:20:11 -07:00
|
|
|
ret_error(r_errcode, e);
|
2012-04-20 16:56:19 +02:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-27 23:07:38 +02:00
|
|
|
CLOVER_API cl_program
|
|
|
|
|
clCreateProgramWithBuiltInKernels(cl_context d_ctx, cl_uint n,
|
|
|
|
|
const cl_device_id *d_devs,
|
|
|
|
|
const char *kernel_names,
|
|
|
|
|
cl_int *r_errcode) try {
|
|
|
|
|
auto &ctx = obj(d_ctx);
|
|
|
|
|
auto devs = objs(d_devs, n);
|
|
|
|
|
|
|
|
|
|
if (any_of([&](const device &dev) {
|
|
|
|
|
return !count(dev, ctx.devices());
|
|
|
|
|
}, devs))
|
|
|
|
|
throw error(CL_INVALID_DEVICE);
|
|
|
|
|
|
|
|
|
|
// No currently supported built-in kernels.
|
|
|
|
|
throw error(CL_INVALID_VALUE);
|
|
|
|
|
|
|
|
|
|
} catch (error &e) {
|
|
|
|
|
ret_error(r_errcode, e);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-10-06 13:52:02 -07:00
|
|
|
CLOVER_API cl_int
|
2013-09-17 23:20:11 -07:00
|
|
|
clRetainProgram(cl_program d_prog) try {
|
|
|
|
|
obj(d_prog).retain();
|
2012-04-20 16:56:19 +02:00
|
|
|
return CL_SUCCESS;
|
2013-09-17 23:20:11 -07:00
|
|
|
|
|
|
|
|
} catch (error &e) {
|
|
|
|
|
return e.get();
|
2012-04-20 16:56:19 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-06 13:52:02 -07:00
|
|
|
CLOVER_API cl_int
|
2013-09-17 23:20:11 -07:00
|
|
|
clReleaseProgram(cl_program d_prog) try {
|
|
|
|
|
if (obj(d_prog).release())
|
|
|
|
|
delete pobj(d_prog);
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
return CL_SUCCESS;
|
2013-09-17 23:20:11 -07:00
|
|
|
|
|
|
|
|
} catch (error &e) {
|
|
|
|
|
return e.get();
|
2012-04-20 16:56:19 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-06 13:52:02 -07:00
|
|
|
CLOVER_API cl_int
|
2013-09-17 23:20:11 -07:00
|
|
|
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 *),
|
2014-10-21 10:33:21 -04:00
|
|
|
void *user_data) try {
|
|
|
|
|
auto &prog = obj(d_prog);
|
|
|
|
|
auto devs = (d_devs ? objs(d_devs, num_devs) :
|
|
|
|
|
ref_vector<device>(prog.context().devices()));
|
|
|
|
|
auto opts = (p_opts ? p_opts : "");
|
2014-10-20 10:34:17 +03:00
|
|
|
|
2016-05-17 16:03:18 +02:00
|
|
|
validate_build_common(prog, num_devs, d_devs, pfn_notify, user_data);
|
2014-10-21 10:33:21 -04:00
|
|
|
|
2016-05-17 16:03:14 +02:00
|
|
|
if (prog.has_source) {
|
|
|
|
|
prog.compile(devs, opts);
|
|
|
|
|
prog.link(devs, opts, { prog });
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 10:33:21 -04:00
|
|
|
return CL_SUCCESS;
|
2016-05-17 16:03:11 +02:00
|
|
|
|
2014-10-21 10:33:21 -04:00
|
|
|
} catch (error &e) {
|
|
|
|
|
return e.get();
|
2014-10-20 10:34:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CLOVER_API cl_int
|
|
|
|
|
clCompileProgram(cl_program d_prog, cl_uint num_devs,
|
|
|
|
|
const cl_device_id *d_devs, const char *p_opts,
|
|
|
|
|
cl_uint num_headers, const cl_program *d_header_progs,
|
|
|
|
|
const char **header_names,
|
|
|
|
|
void (*pfn_notify)(cl_program, void *),
|
|
|
|
|
void *user_data) try {
|
2013-09-17 23:20:11 -07:00
|
|
|
auto &prog = obj(d_prog);
|
|
|
|
|
auto devs = (d_devs ? objs(d_devs, num_devs) :
|
2014-02-18 13:12:52 +01:00
|
|
|
ref_vector<device>(prog.context().devices()));
|
2013-09-17 23:20:11 -07:00
|
|
|
auto opts = (p_opts ? p_opts : "");
|
2014-10-20 10:34:17 +03:00
|
|
|
header_map headers;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
2016-05-17 16:03:18 +02:00
|
|
|
validate_build_common(prog, num_devs, d_devs, pfn_notify, user_data);
|
2012-04-20 16:56:19 +02:00
|
|
|
|
2014-10-21 10:31:56 -04:00
|
|
|
if (bool(num_headers) != bool(header_names))
|
|
|
|
|
throw error(CL_INVALID_VALUE);
|
2012-04-20 16:56:19 +02:00
|
|
|
|
2014-10-21 10:31:56 -04:00
|
|
|
if (!prog.has_source)
|
2014-08-16 16:25:34 +03:00
|
|
|
throw error(CL_INVALID_OPERATION);
|
|
|
|
|
|
2014-10-20 10:34:17 +03:00
|
|
|
for_each([&](const char *name, const program &header) {
|
|
|
|
|
if (!header.has_source)
|
|
|
|
|
throw error(CL_INVALID_OPERATION);
|
|
|
|
|
|
|
|
|
|
if (!any_of(key_equals(name), headers))
|
2015-04-24 12:59:55 +02:00
|
|
|
headers.push_back(std::pair<std::string, std::string>(
|
2014-10-20 10:34:17 +03:00
|
|
|
name, header.source()));
|
|
|
|
|
},
|
|
|
|
|
range(header_names, num_headers),
|
2014-10-11 18:01:36 +02:00
|
|
|
objs<allow_empty_tag>(d_header_progs, num_headers));
|
2014-10-20 10:34:17 +03:00
|
|
|
|
2016-05-17 16:03:14 +02:00
|
|
|
prog.compile(devs, opts, headers);
|
2012-04-20 16:56:19 +02:00
|
|
|
return CL_SUCCESS;
|
|
|
|
|
|
2016-05-17 16:03:11 +02:00
|
|
|
} catch (invalid_build_options_error &e) {
|
|
|
|
|
return CL_INVALID_COMPILER_OPTIONS;
|
|
|
|
|
|
2016-06-19 14:31:59 -07:00
|
|
|
} catch (build_error &e) {
|
|
|
|
|
return CL_COMPILE_PROGRAM_FAILURE;
|
|
|
|
|
|
2012-04-20 16:56:19 +02:00
|
|
|
} catch (error &e) {
|
|
|
|
|
return e.get();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-07 10:40:31 +02:00
|
|
|
CLOVER_API cl_program
|
|
|
|
|
clLinkProgram(cl_context d_ctx, cl_uint num_devs, const cl_device_id *d_devs,
|
|
|
|
|
const char *p_opts, cl_uint num_progs, const cl_program *d_progs,
|
2016-05-08 21:57:34 -07:00
|
|
|
void (*pfn_notify) (cl_program, void *), void *user_data,
|
|
|
|
|
cl_int *r_errcode) try {
|
|
|
|
|
auto &ctx = obj(d_ctx);
|
|
|
|
|
auto devs = (d_devs ? objs(d_devs, num_devs) :
|
|
|
|
|
ref_vector<device>(ctx.devices()));
|
|
|
|
|
auto opts = (p_opts ? p_opts : "");
|
|
|
|
|
auto progs = objs(d_progs, num_progs);
|
|
|
|
|
auto prog = create<program>(ctx);
|
|
|
|
|
|
|
|
|
|
validate_build_common(prog, num_devs, d_devs, pfn_notify, user_data);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
prog().link(devs, opts, progs);
|
|
|
|
|
ret_error(r_errcode, CL_SUCCESS);
|
|
|
|
|
|
|
|
|
|
} catch (build_error &e) {
|
|
|
|
|
ret_error(r_errcode, CL_LINK_PROGRAM_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret_object(prog);
|
|
|
|
|
|
|
|
|
|
} catch (invalid_build_options_error &e) {
|
|
|
|
|
ret_error(r_errcode, CL_INVALID_LINKER_OPTIONS);
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
} catch (error &e) {
|
|
|
|
|
ret_error(r_errcode, e);
|
2015-08-07 10:40:31 +02:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-06 13:52:02 -07:00
|
|
|
CLOVER_API cl_int
|
2012-04-20 16:56:19 +02:00
|
|
|
clUnloadCompiler() {
|
|
|
|
|
return CL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-27 23:07:39 +02:00
|
|
|
CLOVER_API cl_int
|
|
|
|
|
clUnloadPlatformCompiler(cl_platform_id d_platform) {
|
|
|
|
|
return CL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-06 13:52:02 -07:00
|
|
|
CLOVER_API cl_int
|
2013-09-17 23:20:11 -07:00
|
|
|
clGetProgramInfo(cl_program d_prog, cl_program_info param,
|
2013-10-06 13:49:49 -07:00
|
|
|
size_t size, void *r_buf, size_t *r_size) try {
|
|
|
|
|
property_buffer buf { r_buf, size, r_size };
|
2013-09-17 23:20:11 -07:00
|
|
|
auto &prog = obj(d_prog);
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
switch (param) {
|
|
|
|
|
case CL_PROGRAM_REFERENCE_COUNT:
|
2013-09-17 23:20:11 -07:00
|
|
|
buf.as_scalar<cl_uint>() = prog.ref_count();
|
2013-10-06 13:49:49 -07:00
|
|
|
break;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
case CL_PROGRAM_CONTEXT:
|
2014-02-18 15:07:11 +01:00
|
|
|
buf.as_scalar<cl_context>() = desc(prog.context());
|
2013-10-06 13:49:49 -07:00
|
|
|
break;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
case CL_PROGRAM_NUM_DEVICES:
|
2014-02-18 15:07:11 +01:00
|
|
|
buf.as_scalar<cl_uint>() = (prog.devices().size() ?
|
|
|
|
|
prog.devices().size() :
|
2014-02-18 13:12:52 +01:00
|
|
|
prog.context().devices().size());
|
2013-10-06 13:49:49 -07:00
|
|
|
break;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
case CL_PROGRAM_DEVICES:
|
2014-02-18 15:07:11 +01:00
|
|
|
buf.as_vector<cl_device_id>() = (prog.devices().size() ?
|
|
|
|
|
descs(prog.devices()) :
|
2014-02-18 13:12:52 +01:00
|
|
|
descs(prog.context().devices()));
|
2013-10-06 13:49:49 -07:00
|
|
|
break;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
case CL_PROGRAM_SOURCE:
|
2013-09-17 23:20:11 -07:00
|
|
|
buf.as_string() = prog.source();
|
2013-10-06 13:49:49 -07:00
|
|
|
break;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
case CL_PROGRAM_BINARY_SIZES:
|
2013-09-16 21:50:40 -07:00
|
|
|
buf.as_vector<size_t>() = map([&](const device &dev) {
|
2016-05-17 16:03:13 +02:00
|
|
|
return prog.build(dev).binary.size();
|
2013-09-16 21:50:40 -07:00
|
|
|
},
|
|
|
|
|
prog.devices());
|
2013-10-06 13:49:49 -07:00
|
|
|
break;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
case CL_PROGRAM_BINARIES:
|
2013-09-16 21:50:40 -07:00
|
|
|
buf.as_matrix<unsigned char>() = map([&](const device &dev) {
|
2015-04-23 20:13:51 +02:00
|
|
|
std::stringbuf bin;
|
|
|
|
|
std::ostream s(&bin);
|
2016-05-17 16:03:13 +02:00
|
|
|
prog.build(dev).binary.serialize(s);
|
2015-04-23 20:13:51 +02:00
|
|
|
return bin.str();
|
2013-09-16 21:50:40 -07:00
|
|
|
},
|
|
|
|
|
prog.devices());
|
2013-10-06 13:49:49 -07:00
|
|
|
break;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
2014-08-05 19:09:38 +02:00
|
|
|
case CL_PROGRAM_NUM_KERNELS:
|
|
|
|
|
buf.as_scalar<cl_uint>() = prog.symbols().size();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CL_PROGRAM_KERNEL_NAMES:
|
|
|
|
|
buf.as_string() = fold([](const std::string &a, const module::symbol &s) {
|
2015-04-24 12:59:56 +02:00
|
|
|
return ((a.empty() ? "" : a + ";") + s.name);
|
2014-08-05 19:09:38 +02:00
|
|
|
}, std::string(), prog.symbols());
|
|
|
|
|
break;
|
|
|
|
|
|
2012-04-20 16:56:19 +02:00
|
|
|
default:
|
2013-10-06 13:49:49 -07:00
|
|
|
throw error(CL_INVALID_VALUE);
|
2012-04-20 16:56:19 +02:00
|
|
|
}
|
2013-10-06 13:49:49 -07:00
|
|
|
|
|
|
|
|
return CL_SUCCESS;
|
|
|
|
|
|
|
|
|
|
} catch (error &e) {
|
|
|
|
|
return e.get();
|
2012-04-20 16:56:19 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-06 13:52:02 -07:00
|
|
|
CLOVER_API cl_int
|
2013-09-17 23:20:11 -07:00
|
|
|
clGetProgramBuildInfo(cl_program d_prog, cl_device_id d_dev,
|
2012-04-20 16:56:19 +02:00
|
|
|
cl_program_build_info param,
|
2013-10-06 13:49:49 -07:00
|
|
|
size_t size, void *r_buf, size_t *r_size) try {
|
|
|
|
|
property_buffer buf { r_buf, size, r_size };
|
2013-09-17 23:20:11 -07:00
|
|
|
auto &prog = obj(d_prog);
|
|
|
|
|
auto &dev = obj(d_dev);
|
2013-10-06 13:49:49 -07:00
|
|
|
|
2014-02-18 13:12:52 +01:00
|
|
|
if (!count(dev, prog.context().devices()))
|
2012-04-20 16:56:19 +02:00
|
|
|
return CL_INVALID_DEVICE;
|
|
|
|
|
|
|
|
|
|
switch (param) {
|
|
|
|
|
case CL_PROGRAM_BUILD_STATUS:
|
2016-05-17 16:03:13 +02:00
|
|
|
buf.as_scalar<cl_build_status>() = prog.build(dev).status();
|
2013-10-06 13:49:49 -07:00
|
|
|
break;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
case CL_PROGRAM_BUILD_OPTIONS:
|
2016-05-17 16:03:13 +02:00
|
|
|
buf.as_string() = prog.build(dev).opts;
|
2013-10-06 13:49:49 -07:00
|
|
|
break;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
case CL_PROGRAM_BUILD_LOG:
|
2016-05-17 16:03:13 +02:00
|
|
|
buf.as_string() = prog.build(dev).log;
|
2013-10-06 13:49:49 -07:00
|
|
|
break;
|
2012-04-20 16:56:19 +02:00
|
|
|
|
|
|
|
|
default:
|
2013-10-06 13:49:49 -07:00
|
|
|
throw error(CL_INVALID_VALUE);
|
2012-04-20 16:56:19 +02:00
|
|
|
}
|
2013-10-06 13:49:49 -07:00
|
|
|
|
|
|
|
|
return CL_SUCCESS;
|
|
|
|
|
|
|
|
|
|
} catch (error &e) {
|
|
|
|
|
return e.get();
|
2012-04-20 16:56:19 +02:00
|
|
|
}
|