Signed-off-by: Jan Vesely <jan.ves...@rutgers.edu> --- src/gallium/state_trackers/clover/core/kernel.cpp | 162 ++++++++++++---------- 1 file changed, 85 insertions(+), 77 deletions(-)
diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp index 68e91d5..7a88de1 100644 --- a/src/gallium/state_trackers/clover/core/kernel.cpp +++ b/src/gallium/state_trackers/clover/core/kernel.cpp @@ -28,6 +28,82 @@ using namespace clover; +namespace { + template<typename T> + std::vector<uint8_t> + bytes(const T& x) { + return { (uint8_t *)&x, (uint8_t *)&x + sizeof(x) }; + } + + /// + /// Transform buffer \a v from the native byte order into the byte + /// order specified by \a e. + /// + template<typename T> + void + byteswap(T &v, pipe_endian e) { + if (PIPE_ENDIAN_NATIVE != e) + std::reverse(v.begin(), v.end()); + } + + /// + /// Pad buffer \a v to the next multiple of \a n. + /// + template<typename T> + void + align(T &v, size_t n) { + v.resize(util_align_npot(v.size(), n)); + } + + bool + msb(const std::vector<uint8_t> &s) { + if (PIPE_ENDIAN_NATIVE == PIPE_ENDIAN_LITTLE) + return s.back() & 0x80; + else + return s.front() & 0x80; + } + + /// + /// Resize buffer \a v to size \a n using sign or zero extension + /// according to \a ext. + /// + template<typename T> + void + extend(T &v, enum module::argument::ext_type ext, size_t n) { + const size_t m = std::min(v.size(), n); + const bool sign_ext = (ext == module::argument::sign_ext); + const uint8_t fill = (sign_ext && msb(v) ? ~0 : 0); + T w(n, fill); + + if (PIPE_ENDIAN_NATIVE == PIPE_ENDIAN_LITTLE) + std::copy_n(v.begin(), m, w.begin()); + else + std::copy_n(v.end() - m, m, w.end() - m); + + std::swap(v, w); + } + + /// + /// Append buffer \a w to \a v. + /// + template<typename T> + void + insert(T &v, const T &w) { + v.insert(v.end(), w.begin(), w.end()); + } + + /// + /// Append \a n elements to the end of buffer \a v. + /// + template<typename T> + size_t + allocate(T &v, size_t n) { + size_t pos = v.size(); + v.resize(pos + n); + return pos; + } +} + kernel::kernel(clover::program &prog, const std::string &name, const std::vector<module::argument> &margs) : program(prog), _name(name), exec(*this) { @@ -77,6 +153,10 @@ kernel::launch(command_queue &q, return (uint32_t *)&exec.input[h]; }, exec.g_handles); + // Implicit arguments + auto dims = bytes(cl_uint(block_size.size())); + byteswap(dims, q.device().endianness()); + q.pipe->bind_compute_state(q.pipe, st); q.pipe->bind_sampler_states(q.pipe, PIPE_SHADER_COMPUTE, 0, exec.samplers.size(), @@ -89,11 +169,15 @@ kernel::launch(command_queue &q, q.pipe->set_global_binding(q.pipe, 0, exec.g_buffers.size(), exec.g_buffers.data(), g_handles.data()); + // Create local copy for implicit arguments + auto local_input = exec.input; + insert(local_input, dims); + q.pipe->launch_grid(q.pipe, pad_vector(q, block_size, 1).data(), pad_vector(q, reduced_grid_size, 1).data(), find(name_equals(_name), m.syms).offset, - exec.input.data(), exec.input.size()); + local_input.data(), local_input.size()); q.pipe->set_global_binding(q.pipe, 0, exec.g_buffers.size(), NULL, NULL); q.pipe->set_compute_resources(q.pipe, 0, exec.resources.size(), NULL); @@ -206,82 +290,6 @@ kernel::exec_context::unbind() { mem_local = 0; } -namespace { - template<typename T> - std::vector<uint8_t> - bytes(const T& x) { - return { (uint8_t *)&x, (uint8_t *)&x + sizeof(x) }; - } - - /// - /// Transform buffer \a v from the native byte order into the byte - /// order specified by \a e. - /// - template<typename T> - void - byteswap(T &v, pipe_endian e) { - if (PIPE_ENDIAN_NATIVE != e) - std::reverse(v.begin(), v.end()); - } - - /// - /// Pad buffer \a v to the next multiple of \a n. - /// - template<typename T> - void - align(T &v, size_t n) { - v.resize(util_align_npot(v.size(), n)); - } - - bool - msb(const std::vector<uint8_t> &s) { - if (PIPE_ENDIAN_NATIVE == PIPE_ENDIAN_LITTLE) - return s.back() & 0x80; - else - return s.front() & 0x80; - } - - /// - /// Resize buffer \a v to size \a n using sign or zero extension - /// according to \a ext. - /// - template<typename T> - void - extend(T &v, enum module::argument::ext_type ext, size_t n) { - const size_t m = std::min(v.size(), n); - const bool sign_ext = (ext == module::argument::sign_ext); - const uint8_t fill = (sign_ext && msb(v) ? ~0 : 0); - T w(n, fill); - - if (PIPE_ENDIAN_NATIVE == PIPE_ENDIAN_LITTLE) - std::copy_n(v.begin(), m, w.begin()); - else - std::copy_n(v.end() - m, m, w.end() - m); - - std::swap(v, w); - } - - /// - /// Append buffer \a w to \a v. - /// - template<typename T> - void - insert(T &v, const T &w) { - v.insert(v.end(), w.begin(), w.end()); - } - - /// - /// Append \a n elements to the end of buffer \a v. - /// - template<typename T> - size_t - allocate(T &v, size_t n) { - size_t pos = v.size(); - v.resize(pos + n); - return pos; - } -} - kernel::argument::argument() : _set(false) { } -- 1.9.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev