summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/clover/api
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2013-10-06 13:49:05 -0700
committerFrancisco Jerez <[email protected]>2013-10-21 10:47:02 -0700
commit7d61769e447e47022bea5e9fd415344b45a5a050 (patch)
treeda8e1ad5f6af1f326a8f8f1cf0711c0a2a0057fc /src/gallium/state_trackers/clover/api
parent099d281b38fae791300984964fab1124b0eb14d2 (diff)
clover: Switch to the new utility code.
Tested-by: Tom Stellard <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/api')
-rw-r--r--src/gallium/state_trackers/clover/api/context.cpp2
-rw-r--r--src/gallium/state_trackers/clover/api/kernel.cpp25
-rw-r--r--src/gallium/state_trackers/clover/api/program.cpp28
-rw-r--r--src/gallium/state_trackers/clover/api/transfer.cpp138
-rw-r--r--src/gallium/state_trackers/clover/api/util.hpp7
5 files changed, 103 insertions, 97 deletions
diff --git a/src/gallium/state_trackers/clover/api/context.cpp b/src/gallium/state_trackers/clover/api/context.cpp
index 371744120ee..8586b3ece25 100644
--- a/src/gallium/state_trackers/clover/api/context.cpp
+++ b/src/gallium/state_trackers/clover/api/context.cpp
@@ -37,7 +37,7 @@ clCreateContext(const cl_context_properties *props, cl_uint num_devs,
(!pfn_notify && user_data))
throw error(CL_INVALID_VALUE);
- if (any_of(is_zero<cl_device_id>, devs, devs + num_devs))
+ if (any_of(is_zero(), range(devs, num_devs)))
throw error(CL_INVALID_DEVICE);
for (auto p : mprops) {
diff --git a/src/gallium/state_trackers/clover/api/kernel.cpp b/src/gallium/state_trackers/clover/api/kernel.cpp
index 13113a22b8e..24b17b6eb3b 100644
--- a/src/gallium/state_trackers/clover/api/kernel.cpp
+++ b/src/gallium/state_trackers/clover/api/kernel.cpp
@@ -202,16 +202,16 @@ namespace {
if (&kern->prog.ctx != &q->ctx ||
any_of([&](const cl_event ev) {
return &ev->ctx != &q->ctx;
- }, deps, deps + num_deps))
+ }, range(deps, num_deps)))
throw error(CL_INVALID_CONTEXT);
if (bool(num_deps) != bool(deps) ||
- any_of(is_zero<cl_event>, deps, deps + num_deps))
+ any_of(is_zero(), range(deps, num_deps)))
throw error(CL_INVALID_EVENT_WAIT_LIST);
if (any_of([](std::unique_ptr<kernel::argument> &arg) {
return !arg->set();
- }, kern->args.begin(), kern->args.end()))
+ }, kern->args))
throw error(CL_INVALID_KERNEL_ARGS);
if (!kern->prog.binaries().count(&q->dev))
@@ -220,23 +220,21 @@ namespace {
if (dims < 1 || dims > q->dev.max_block_size().size())
throw error(CL_INVALID_WORK_DIMENSION);
- if (!grid_size || any_of(is_zero<size_t>, grid_size, grid_size + dims))
+ if (!grid_size || any_of(is_zero(), range(grid_size, dims)))
throw error(CL_INVALID_GLOBAL_WORK_SIZE);
if (block_size) {
if (any_of([](size_t b, size_t max) {
return b == 0 || b > max;
- }, block_size, block_size + dims,
- q->dev.max_block_size().begin()))
+ }, range(block_size, dims),
+ q->dev.max_block_size()))
throw error(CL_INVALID_WORK_ITEM_SIZE);
- if (any_of([](size_t b, size_t g) {
- return g % b;
- }, block_size, block_size + dims, grid_size))
+ if (any_of(modulus(), range(grid_size, dims),
+ range(block_size, dims)))
throw error(CL_INVALID_WORK_GROUP_SIZE);
- if (fold(std::multiplies<size_t>(), 1u,
- block_size, block_size + dims) >
+ if (fold(multiplies(), 1u, range(block_size, dims)) >
q->dev.max_threads_per_block())
throw error(CL_INVALID_WORK_GROUP_SIZE);
}
@@ -250,9 +248,8 @@ namespace {
const std::vector<size_t> &grid_offset,
const std::vector<size_t> &grid_size,
const std::vector<size_t> &block_size) {
- const std::vector<size_t> reduced_grid_size = map(
- std::divides<size_t>(), grid_size.begin(), grid_size.end(),
- block_size.begin());
+ const std::vector<size_t> reduced_grid_size =
+ map(divides(), grid_size, block_size);
return [=](event &) {
kern->launch(*q, grid_offset, reduced_grid_size, block_size);
diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp
index 6e5ca08d76b..2ef3a2eced4 100644
--- a/src/gallium/state_trackers/clover/api/program.cpp
+++ b/src/gallium/state_trackers/clover/api/program.cpp
@@ -35,7 +35,7 @@ clCreateProgramWithSource(cl_context ctx, cl_uint count,
throw error(CL_INVALID_CONTEXT);
if (!count || !strings ||
- any_of(is_zero<const char *>, strings, strings + count))
+ any_of(is_zero(), range(strings, count)))
throw error(CL_INVALID_VALUE);
// Concatenate all the provided fragments together
@@ -66,7 +66,7 @@ clCreateProgramWithBinary(cl_context ctx, cl_uint count,
if (any_of([&](const cl_device_id dev) {
return !ctx->has_device(dev);
- }, devs, devs + count))
+ }, range(devs, count)))
throw error(CL_INVALID_DEVICE);
// Deserialize the provided binaries,
@@ -85,26 +85,23 @@ clCreateProgramWithBinary(cl_context ctx, cl_uint count,
return { CL_INVALID_BINARY, {} };
}
},
- binaries, binaries + count, lengths);
+ range(binaries, count),
+ range(lengths, count));
// update the status array,
if (status_ret)
- std::transform(modules.begin(), modules.end(), status_ret,
- keys<cl_int, module>);
+ copy(map(keys(), modules), status_ret);
- if (any_of(key_equals<cl_int, module>(CL_INVALID_VALUE),
- modules.begin(), modules.end()))
+ if (any_of(key_equals(CL_INVALID_VALUE), modules))
throw error(CL_INVALID_VALUE);
- if (any_of(key_equals<cl_int, module>(CL_INVALID_BINARY),
- modules.begin(), modules.end()))
+ if (any_of(key_equals(CL_INVALID_BINARY), modules))
throw error(CL_INVALID_BINARY);
// initialize a program object with them.
ret_error(errcode_ret, CL_SUCCESS);
return new program(*ctx, { devs, devs + count },
- map(values<cl_int, module>,
- modules.begin(), modules.end()));
+ map(values(), modules));
} catch (error &e) {
ret_error(errcode_ret, e);
@@ -148,7 +145,7 @@ clBuildProgram(cl_program prog, cl_uint count, const cl_device_id *devs,
if (devs) {
if (any_of([&](const cl_device_id dev) {
return !prog->ctx.has_device(dev);
- }, devs, devs + count))
+ }, range(devs, count)))
throw error(CL_INVALID_DEVICE);
prog->build({ devs, devs + count }, opts);
@@ -189,8 +186,7 @@ clGetProgramInfo(cl_program prog, cl_program_info param,
case CL_PROGRAM_DEVICES:
return vector_property<cl_device_id>(
buf, size, size_ret,
- map(keys<device *, module>,
- prog->binaries().begin(), prog->binaries().end()));
+ map(keys(), prog->binaries()));
case CL_PROGRAM_SOURCE:
return string_property(buf, size, size_ret, prog->source());
@@ -204,7 +200,7 @@ clGetProgramInfo(cl_program prog, cl_program_info param,
ent.second.serialize(s);
return bin.size();
},
- prog->binaries().begin(), prog->binaries().end()));
+ prog->binaries()));
case CL_PROGRAM_BINARIES:
return matrix_property<unsigned char>(
@@ -215,7 +211,7 @@ clGetProgramInfo(cl_program prog, cl_program_info param,
ent.second.serialize(s);
return bin;
},
- prog->binaries().begin(), prog->binaries().end()));
+ prog->binaries()));
default:
return CL_INVALID_VALUE;
diff --git a/src/gallium/state_trackers/clover/api/transfer.cpp b/src/gallium/state_trackers/clover/api/transfer.cpp
index 43036da528d..d2aae67bebe 100644
--- a/src/gallium/state_trackers/clover/api/transfer.cpp
+++ b/src/gallium/state_trackers/clover/api/transfer.cpp
@@ -29,7 +29,12 @@
using namespace clover;
namespace {
- typedef resource::point point;
+ typedef resource::vector vector_t;
+
+ vector_t
+ vector(const size_t *p) {
+ return range(p, 3);
+ }
///
/// Common argument checking shared by memory transfer commands.
@@ -40,12 +45,12 @@ namespace {
throw error(CL_INVALID_COMMAND_QUEUE);
if (bool(num_deps) != bool(deps) ||
- any_of(is_zero<cl_event>, deps, deps + num_deps))
+ any_of(is_zero(), range(deps, num_deps)))
throw error(CL_INVALID_EVENT_WAIT_LIST);
if (any_of([&](const cl_event ev) {
return &ev->ctx != &q->ctx;
- }, deps, deps + num_deps))
+ }, range(deps, num_deps)))
throw error(CL_INVALID_CONTEXT);
}
@@ -89,7 +94,8 @@ namespace {
static mapping
get(cl_command_queue q, memory_obj *obj, cl_map_flags flags,
size_t offset, size_t size) {
- return { *q, obj->resource(q), flags, true, { offset }, { size, 1, 1 }};
+ return { *q, obj->resource(q), flags, true,
+ {{ offset }}, {{ size, 1, 1 }}};
}
};
@@ -100,21 +106,24 @@ namespace {
template<typename T, typename S>
std::function<void (event &)>
soft_copy_op(cl_command_queue q,
- T dst_obj, const point &dst_orig, const point &dst_pitch,
- S src_obj, const point &src_orig, const point &src_pitch,
- const point &region) {
+ T dst_obj, const vector_t &dst_orig, const vector_t &dst_pitch,
+ S src_obj, const vector_t &src_orig, const vector_t &src_pitch,
+ const vector_t &region) {
return [=](event &) {
auto dst = _map<T>::get(q, dst_obj, CL_MAP_WRITE,
- dst_pitch(dst_orig), dst_pitch(region));
+ dot(dst_pitch, dst_orig),
+ dst_pitch[2] * region[2]);
auto src = _map<S>::get(q, src_obj, CL_MAP_READ,
- src_pitch(src_orig), src_pitch(region));
- point p;
-
- for (p[2] = 0; p[2] < region[2]; ++p[2]) {
- for (p[1] = 0; p[1] < region[1]; ++p[1]) {
- std::memcpy(static_cast<char *>(dst) + dst_pitch(p),
- static_cast<const char *>(src) + src_pitch(p),
- src_pitch[0] * region[0]);
+ dot(src_pitch, src_orig),
+ src_pitch[2] * region[2]);
+ vector_t v = {};
+
+ for (v[2] = 0; v[2] < region[2]; ++v[2]) {
+ for (v[1] = 0; v[1] < region[1]; ++v[1]) {
+ std::memcpy(
+ static_cast<char *>(dst) + dot(dst_pitch, v),
+ static_cast<const char *>(src) + dot(src_pitch, v),
+ src_pitch[0] * region[0]);
}
}
};
@@ -125,8 +134,8 @@ namespace {
///
template<typename T, typename S>
std::function<void (event &)>
- hard_copy_op(cl_command_queue q, T dst_obj, const point &dst_orig,
- S src_obj, const point &src_orig, const point &region) {
+ hard_copy_op(cl_command_queue q, T dst_obj, const vector_t &dst_orig,
+ S src_obj, const vector_t &src_orig, const vector_t &region) {
return [=](event &) {
dst_obj->resource(q).copy(*q, dst_orig, region,
src_obj->resource(q), src_orig);
@@ -148,9 +157,9 @@ clEnqueueReadBuffer(cl_command_queue q, cl_mem obj, cl_bool blocking,
hard_event *hev = new hard_event(
*q, CL_COMMAND_READ_BUFFER, { deps, deps + num_deps },
soft_copy_op(q,
- ptr, { 0 }, { 1 },
- obj, { offset }, { 1 },
- { size, 1, 1 }));
+ ptr, {{ 0 }}, {{ 1 }},
+ obj, {{ offset }}, {{ 1 }},
+ {{ size, 1, 1 }}));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -173,9 +182,9 @@ clEnqueueWriteBuffer(cl_command_queue q, cl_mem obj, cl_bool blocking,
hard_event *hev = new hard_event(
*q, CL_COMMAND_WRITE_BUFFER, { deps, deps + num_deps },
soft_copy_op(q,
- obj, { offset }, { 1 },
- ptr, { 0 }, { 1 },
- { size, 1, 1 }));
+ obj, {{ offset }}, {{ 1 }},
+ ptr, {{ 0 }}, {{ 1 }},
+ {{ size, 1, 1 }}));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -202,11 +211,11 @@ clEnqueueReadBufferRect(cl_command_queue q, cl_mem obj, cl_bool blocking,
hard_event *hev = new hard_event(
*q, CL_COMMAND_READ_BUFFER_RECT, { deps, deps + num_deps },
soft_copy_op(q,
- ptr, host_origin,
- { 1, host_row_pitch, host_slice_pitch },
- obj, obj_origin,
- { 1, obj_row_pitch, obj_slice_pitch },
- region));
+ ptr, vector(host_origin),
+ {{ 1, host_row_pitch, host_slice_pitch }},
+ obj, vector(obj_origin),
+ {{ 1, obj_row_pitch, obj_slice_pitch }},
+ vector(region)));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -233,11 +242,11 @@ clEnqueueWriteBufferRect(cl_command_queue q, cl_mem obj, cl_bool blocking,
hard_event *hev = new hard_event(
*q, CL_COMMAND_WRITE_BUFFER_RECT, { deps, deps + num_deps },
soft_copy_op(q,
- obj, obj_origin,
- { 1, obj_row_pitch, obj_slice_pitch },
- ptr, host_origin,
- { 1, host_row_pitch, host_slice_pitch },
- region));
+ obj, vector(obj_origin),
+ {{ 1, obj_row_pitch, obj_slice_pitch }},
+ ptr, vector(host_origin),
+ {{ 1, host_row_pitch, host_slice_pitch }},
+ vector(region)));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -257,9 +266,9 @@ clEnqueueCopyBuffer(cl_command_queue q, cl_mem src_obj, cl_mem dst_obj,
hard_event *hev = new hard_event(
*q, CL_COMMAND_COPY_BUFFER, { deps, deps + num_deps },
- hard_copy_op(q, dst_obj, { dst_offset },
- src_obj, { src_offset },
- { size, 1, 1 }));
+ hard_copy_op(q, dst_obj, {{ dst_offset }},
+ src_obj, {{ src_offset }},
+ {{ size, 1, 1 }}));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -283,11 +292,11 @@ clEnqueueCopyBufferRect(cl_command_queue q, cl_mem src_obj, cl_mem dst_obj,
hard_event *hev = new hard_event(
*q, CL_COMMAND_COPY_BUFFER_RECT, { deps, deps + num_deps },
soft_copy_op(q,
- dst_obj, dst_origin,
- { 1, dst_row_pitch, dst_slice_pitch },
- src_obj, src_origin,
- { 1, src_row_pitch, src_slice_pitch },
- region));
+ dst_obj, vector(dst_origin),
+ {{ 1, dst_row_pitch, dst_slice_pitch }},
+ src_obj, vector(src_origin),
+ {{ 1, src_row_pitch, src_slice_pitch }},
+ vector(region)));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -314,10 +323,10 @@ clEnqueueReadImage(cl_command_queue q, cl_mem obj, cl_bool blocking,
*q, CL_COMMAND_READ_IMAGE, { deps, deps + num_deps },
soft_copy_op(q,
ptr, {},
- { 1, row_pitch, slice_pitch },
- obj, origin,
- { 1, img->row_pitch(), img->slice_pitch() },
- region));
+ {{ 1, row_pitch, slice_pitch }},
+ obj, vector(origin),
+ {{ 1, img->row_pitch(), img->slice_pitch() }},
+ vector(region)));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -343,11 +352,11 @@ clEnqueueWriteImage(cl_command_queue q, cl_mem obj, cl_bool blocking,
hard_event *hev = new hard_event(
*q, CL_COMMAND_WRITE_IMAGE, { deps, deps + num_deps },
soft_copy_op(q,
- obj, origin,
- { 1, img->row_pitch(), img->slice_pitch() },
+ obj, vector(origin),
+ {{ 1, img->row_pitch(), img->slice_pitch() }},
ptr, {},
- { 1, row_pitch, slice_pitch },
- region));
+ {{ 1, row_pitch, slice_pitch }},
+ vector(region)));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -371,7 +380,10 @@ clEnqueueCopyImage(cl_command_queue q, cl_mem src_obj, cl_mem dst_obj,
hard_event *hev = new hard_event(
*q, CL_COMMAND_COPY_IMAGE, { deps, deps + num_deps },
- hard_copy_op(q, dst_obj, dst_origin, src_obj, src_origin, region));
+ hard_copy_op(q,
+ dst_obj, vector(dst_origin),
+ src_obj, vector(src_origin),
+ vector(region)));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -395,11 +407,11 @@ clEnqueueCopyImageToBuffer(cl_command_queue q, cl_mem src_obj, cl_mem dst_obj,
hard_event *hev = new hard_event(
*q, CL_COMMAND_COPY_IMAGE_TO_BUFFER, { deps, deps + num_deps },
soft_copy_op(q,
- dst_obj, { dst_offset },
- { 0, 0, 0 },
- src_obj, src_origin,
- { 1, src_img->row_pitch(), src_img->slice_pitch() },
- region));
+ dst_obj, {{ dst_offset }},
+ {{ 0, 0, 0 }},
+ src_obj, vector(src_origin),
+ {{ 1, src_img->row_pitch(), src_img->slice_pitch() }},
+ vector(region)));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -423,11 +435,11 @@ clEnqueueCopyBufferToImage(cl_command_queue q, cl_mem src_obj, cl_mem dst_obj,
hard_event *hev = new hard_event(
*q, CL_COMMAND_COPY_BUFFER_TO_IMAGE, { deps, deps + num_deps },
soft_copy_op(q,
- dst_obj, dst_origin,
- { 1, dst_img->row_pitch(), dst_img->slice_pitch() },
- src_obj, { src_offset },
- { 0, 0, 0 },
- region));
+ dst_obj, vector(dst_origin),
+ {{ 1, dst_img->row_pitch(), dst_img->slice_pitch() }},
+ src_obj, {{ src_offset }},
+ {{ 0, 0, 0 }},
+ vector(region)));
ret_object(ev, hev);
return CL_SUCCESS;
@@ -448,7 +460,7 @@ clEnqueueMapBuffer(cl_command_queue q, cl_mem obj, cl_bool blocking,
throw error(CL_INVALID_VALUE);
void *map = obj->resource(q).add_map(
- *q, flags, blocking, { offset }, { size });
+ *q, flags, blocking, {{ offset }}, {{ size }});
ret_object(ev, new hard_event(*q, CL_COMMAND_MAP_BUFFER,
{ deps, deps + num_deps }));
@@ -473,7 +485,7 @@ clEnqueueMapImage(cl_command_queue q, cl_mem obj, cl_bool blocking,
validate_obj(q, img);
void *map = obj->resource(q).add_map(
- *q, flags, blocking, origin, region);
+ *q, flags, blocking, vector(origin), vector(region));
ret_object(ev, new hard_event(*q, CL_COMMAND_MAP_IMAGE,
{ deps, deps + num_deps }));
diff --git a/src/gallium/state_trackers/clover/api/util.hpp b/src/gallium/state_trackers/clover/api/util.hpp
index f4febb3c529..d9d9b7a73cb 100644
--- a/src/gallium/state_trackers/clover/api/util.hpp
+++ b/src/gallium/state_trackers/clover/api/util.hpp
@@ -29,6 +29,7 @@
#include <map>
#include "core/base.hpp"
+#include "util/algorithm.hpp"
#include "pipe/p_compiler.h"
namespace clover {
@@ -49,9 +50,9 @@ namespace clover {
if (buf)
for_each([](typename V::value_type src, T *dst) {
if (dst)
- std::copy(src.begin(), src.end(), dst);
+ copy(src, dst);
},
- v.begin(), v.end(), (T **)buf);
+ v, range((T **)buf, v.size()));
return CL_SUCCESS;
}
@@ -69,7 +70,7 @@ namespace clover {
if (size_ret)
*size_ret = sizeof(T) * v.size();
if (buf)
- std::copy(v.begin(), v.end(), (T *)buf);
+ copy(v, (T *)buf);
return CL_SUCCESS;
}