Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. //
  2. // Copyright 2012 Francisco Jerez
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a
  5. // copy of this software and associated documentation files (the "Software"),
  6. // to deal in the Software without restriction, including without limitation
  7. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. // and/or sell copies of the Software, and to permit persons to whom the
  9. // Software is furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. // OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22.  
  23. #include "core/device.hpp"
  24. #include "pipe/p_screen.h"
  25. #include "pipe/p_state.h"
  26.  
  27. using namespace clover;
  28.  
  29. namespace {
  30.    template<typename T>
  31.    std::vector<T>
  32.    get_compute_param(pipe_screen *pipe, pipe_compute_cap cap) {
  33.       int sz = pipe->get_compute_param(pipe, cap, NULL);
  34.       std::vector<T> v(sz / sizeof(T));
  35.  
  36.       pipe->get_compute_param(pipe, cap, &v.front());
  37.       return v;
  38.    }
  39. }
  40.  
  41. _cl_device_id::_cl_device_id(clover::platform &platform,
  42.                              pipe_loader_device *ldev) :
  43.    platform(platform), ldev(ldev) {
  44.    pipe = pipe_loader_create_screen(ldev, PIPE_SEARCH_DIR);
  45.    if (!pipe || !pipe->get_param(pipe, PIPE_CAP_COMPUTE))
  46.       throw error(CL_INVALID_DEVICE);
  47. }
  48.  
  49. _cl_device_id::_cl_device_id(_cl_device_id &&dev) :
  50.    platform(dev.platform), pipe(dev.pipe), ldev(dev.ldev) {
  51.    dev.pipe = NULL;
  52.    dev.ldev = NULL;
  53. }
  54.  
  55. _cl_device_id::~_cl_device_id() {
  56.    if (pipe)
  57.       pipe->destroy(pipe);
  58.    if (ldev)
  59.       pipe_loader_release(&ldev, 1);
  60. }
  61.  
  62. _cl_device_id &
  63. _cl_device_id::operator=(_cl_device_id dev) {
  64.    assert(&platform == &dev.platform);
  65.  
  66.    std::swap(pipe, dev.pipe);
  67.    std::swap(ldev, dev.ldev);
  68.  
  69.    return *this;
  70. }
  71.  
  72. cl_device_type
  73. _cl_device_id::type() const {
  74.    switch (ldev->type) {
  75.    case PIPE_LOADER_DEVICE_SOFTWARE:
  76.       return CL_DEVICE_TYPE_CPU;
  77.    case PIPE_LOADER_DEVICE_PCI:
  78.       return CL_DEVICE_TYPE_GPU;
  79.    default:
  80.       assert(0);
  81.       return 0;
  82.    }
  83. }
  84.  
  85. cl_uint
  86. _cl_device_id::vendor_id() const {
  87.    switch (ldev->type) {
  88.    case PIPE_LOADER_DEVICE_SOFTWARE:
  89.       return 0;
  90.    case PIPE_LOADER_DEVICE_PCI:
  91.       return ldev->u.pci.vendor_id;
  92.    default:
  93.       assert(0);
  94.       return 0;
  95.    }
  96. }
  97.  
  98. size_t
  99. _cl_device_id::max_images_read() const {
  100.    return PIPE_MAX_SHADER_RESOURCES;
  101. }
  102.  
  103. size_t
  104. _cl_device_id::max_images_write() const {
  105.    return PIPE_MAX_SHADER_RESOURCES;
  106. }
  107.  
  108. cl_uint
  109. _cl_device_id::max_image_levels_2d() const {
  110.    return pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_2D_LEVELS);
  111. }
  112.  
  113. cl_uint
  114. _cl_device_id::max_image_levels_3d() const {
  115.    return pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_3D_LEVELS);
  116. }
  117.  
  118. cl_uint
  119. _cl_device_id::max_samplers() const {
  120.    return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
  121.                                  PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS);
  122. }
  123.  
  124. cl_ulong
  125. _cl_device_id::max_mem_global() const {
  126.    return get_compute_param<uint64_t>(pipe,
  127.                                       PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE)[0];
  128. }
  129.  
  130. cl_ulong
  131. _cl_device_id::max_mem_local() const {
  132.    return get_compute_param<uint64_t>(pipe,
  133.                                       PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE)[0];
  134. }
  135.  
  136. cl_ulong
  137. _cl_device_id::max_mem_input() const {
  138.    return get_compute_param<uint64_t>(pipe,
  139.                                       PIPE_COMPUTE_CAP_MAX_INPUT_SIZE)[0];
  140. }
  141.  
  142. cl_ulong
  143. _cl_device_id::max_const_buffer_size() const {
  144.    return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
  145.                                  PIPE_SHADER_CAP_MAX_CONSTS) * 16;
  146. }
  147.  
  148. cl_uint
  149. _cl_device_id::max_const_buffers() const {
  150.    return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
  151.                                  PIPE_SHADER_CAP_MAX_CONST_BUFFERS);
  152. }
  153.  
  154. size_t
  155. _cl_device_id::max_threads_per_block() const {
  156.    return get_compute_param<uint64_t>(
  157.       pipe, PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK)[0];
  158. }
  159.  
  160. cl_ulong
  161. _cl_device_id::max_mem_alloc_size() const {
  162.    return get_compute_param<uint64_t>(pipe,
  163.                                       PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE)[0];
  164. }
  165.  
  166. std::vector<size_t>
  167. _cl_device_id::max_block_size() const {
  168.    auto v = get_compute_param<uint64_t>(pipe, PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE);
  169.    return { v.begin(), v.end() };
  170. }
  171.  
  172. std::string
  173. _cl_device_id::device_name() const {
  174.    return pipe->get_name(pipe);
  175. }
  176.  
  177. std::string
  178. _cl_device_id::vendor_name() const {
  179.    return pipe->get_vendor(pipe);
  180. }
  181.  
  182. enum pipe_shader_ir
  183. _cl_device_id::ir_format() const {
  184.    return (enum pipe_shader_ir) pipe->get_shader_param(pipe,
  185.                                                   PIPE_SHADER_COMPUTE,
  186.                                                   PIPE_SHADER_CAP_PREFERRED_IR);
  187. }
  188.  
  189. std::string
  190. _cl_device_id::ir_target() const {
  191.    std::vector<char> target = get_compute_param<char>(pipe,
  192.                                                     PIPE_COMPUTE_CAP_IR_TARGET);
  193.    return { target.data() };
  194. }
  195.  
  196. enum pipe_endian
  197. _cl_device_id::endianness() const {
  198.    return (enum pipe_endian)pipe->get_param(pipe, PIPE_CAP_ENDIANNESS);
  199. }
  200.