clover: add support command queue properties

Fixes api queue_properties_queries

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7642>
This commit is contained in:
Dave Airlie 2020-11-05 11:39:05 +10:00
parent 0272b6b1ba
commit e42a7fa037
3 changed files with 67 additions and 20 deletions

View file

@ -91,7 +91,11 @@ clGetCommandQueueInfo(cl_command_queue d_q, cl_command_queue_info param,
break;
case CL_QUEUE_PROPERTIES:
buf.as_scalar<cl_command_queue_properties>() = q.properties();
buf.as_scalar<cl_command_queue_properties>() = q.props();
break;
case CL_QUEUE_PROPERTIES_ARRAY:
buf.as_vector<cl_queue_properties>() = q.properties();
break;
default:
@ -114,22 +118,29 @@ clFlush(cl_command_queue d_q) try {
}
CLOVER_API cl_command_queue
clCreateCommandQueueWithProperties(cl_context context, cl_device_id device,
const cl_queue_properties *properties,
cl_int *errcode_ret) try {
cl_command_queue_properties props = 0;
if (properties) {
for (auto idx = 0; properties[idx]; idx += 2) {
if (properties[idx] == CL_QUEUE_PROPERTIES)
props |= properties[idx + 1];
else
throw error(CL_INVALID_VALUE);
}
}
clCreateCommandQueueWithProperties(cl_context d_ctx, cl_device_id d_dev,
const cl_queue_properties *d_properties,
cl_int *r_errcode) try {
auto &ctx = obj(d_ctx);
auto &dev = obj(d_dev);
return clCreateCommandQueue(context, device, props, errcode_ret);
if (!count(dev, ctx.devices()))
throw error(CL_INVALID_DEVICE);
ret_error(r_errcode, CL_SUCCESS);
std::vector<cl_queue_properties> properties;
if (d_properties) {
int idx = -1;
/* these come in pairs, bail if the first is 0 */
do {
idx++;
properties.push_back(d_properties[idx]);
} while (d_properties[idx & ~1]);
}
return new command_queue(ctx, dev, properties);
} catch (error &e) {
ret_error(errcode_ret, e);
ret_error(r_errcode, e);
return NULL;
}

View file

@ -44,7 +44,33 @@ namespace {
command_queue::command_queue(clover::context &ctx, clover::device &dev,
cl_command_queue_properties props) :
context(ctx), device(dev), props(props) {
context(ctx), device(dev), _props(props) {
pipe = dev.pipe->context_create(dev.pipe, NULL, PIPE_CONTEXT_COMPUTE_ONLY);
if (!pipe)
throw error(CL_INVALID_DEVICE);
if (ctx.notify) {
struct pipe_debug_callback cb;
memset(&cb, 0, sizeof(cb));
cb.debug_message = &debug_notify_callback;
cb.data = this;
if (pipe->set_debug_callback)
pipe->set_debug_callback(pipe, &cb);
}
}
command_queue::command_queue(clover::context &ctx, clover::device &dev,
std::vector<cl_queue_properties> properties) :
context(ctx), device(dev), _properties(properties) {
for(std::vector<cl_queue_properties>::size_type i = 0; i != properties.size(); i += 2) {
if (properties[i] == 0)
break;
if (properties[i] == CL_QUEUE_PROPERTIES)
_props |= properties[i + 1];
else if (properties[i] != CL_QUEUE_SIZE)
throw error(CL_INVALID_VALUE);
}
pipe = dev.pipe->context_create(dev.pipe, NULL, PIPE_CONTEXT_COMPUTE_ONLY);
if (!pipe)
throw error(CL_INVALID_DEVICE);
@ -88,13 +114,18 @@ command_queue::flush_unlocked() {
}
cl_command_queue_properties
command_queue::props() const {
return _props;
}
std::vector<cl_queue_properties>
command_queue::properties() const {
return props;
return _properties;
}
bool
command_queue::profiling_enabled() const {
return props & CL_QUEUE_PROFILING_ENABLE;
return _props & CL_QUEUE_PROFILING_ENABLE;
}
void

View file

@ -38,6 +38,8 @@ namespace clover {
class command_queue : public ref_counter, public _cl_command_queue {
public:
command_queue(clover::context &ctx, clover::device &dev,
std::vector<cl_queue_properties> properties);
command_queue(clover::context &ctx, clover::device &dev,
cl_command_queue_properties props);
~command_queue();
@ -48,7 +50,9 @@ namespace clover {
void flush();
cl_command_queue_properties properties() const;
cl_command_queue_properties props() const;
std::vector<cl_queue_properties> properties() const;
bool profiling_enabled() const;
const intrusive_ref<clover::context> context;
@ -70,7 +74,8 @@ namespace clover {
// Use this instead of flush() if `queued_events_mutex` is acquired.
void flush_unlocked();
cl_command_queue_properties props;
std::vector<cl_queue_properties> _properties;
cl_command_queue_properties _props;
pipe_context *pipe;
std::mutex queued_events_mutex;
std::deque<intrusive_ref<hard_event>> queued_events;