Home | History | Annotate | Download | only in ocl
      1 /*
      2  * cl_device.h - CL device
      3  *
      4  *  Copyright (c) 2015 Intel Corporation
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  *
     18  * Author: Wind Yuan <feng.yuan (at) intel.com>
     19  */
     20 
     21 #ifndef XCAM_CL_DEVICE_H
     22 #define XCAM_CL_DEVICE_H
     23 
     24 #include <xcam_std.h>
     25 #include <xcam_mutex.h>
     26 #include <CL/cl.h>
     27 
     28 namespace XCam {
     29 
     30 class CLContext;
     31 
     32 struct CLDevieInfo {
     33     uint32_t  max_compute_unit;
     34     uint32_t  max_work_item_dims;
     35     size_t    max_work_item_sizes [3];
     36     size_t    max_work_group_size;
     37     uint32_t  image_pitch_alignment;
     38 
     39     CLDevieInfo ()
     40         : max_compute_unit (0)
     41         , max_work_item_dims (0)
     42         , max_work_group_size (0)
     43         , image_pitch_alignment (4)
     44     {
     45         xcam_mem_clear (max_work_item_sizes);
     46     }
     47 };
     48 
     49 // terminate () must called before program exit
     50 
     51 class CLDevice {
     52 public:
     53     ~CLDevice ();
     54     static SmartPtr<CLDevice> instance ();
     55 
     56     bool is_inited () const {
     57         return _inited;
     58     }
     59     const CLDevieInfo &get_device_info () {
     60         return _device_info;
     61     }
     62     cl_device_id get_device_id () {
     63         return _device_id;
     64     }
     65     cl_platform_id get_platform_id () {
     66         return _platform_id;
     67     }
     68     char* get_platform_name () {
     69         return _platform_name;
     70     }
     71 
     72     SmartPtr<CLContext> get_context ();
     73     void *get_extension_function (const char *func_name);
     74     void terminate ();
     75 
     76 private:
     77     CLDevice ();
     78     bool init ();
     79     bool query_device_info (cl_device_id device_id, CLDevieInfo &info);
     80     bool create_default_context ();
     81 
     82     XCAM_DEAD_COPY (CLDevice);
     83 
     84 private:
     85     static SmartPtr<CLDevice>  _instance;
     86     static Mutex               _instance_mutex;
     87     char                       _platform_name[XCAM_CL_MAX_STR_SIZE];
     88     cl_platform_id             _platform_id;
     89     cl_device_id               _device_id;
     90     CLDevieInfo                _device_info;
     91     bool                       _inited;
     92 
     93     //Mutex                      _context_mutex;
     94     SmartPtr<CLContext>        _default_context;
     95 };
     96 
     97 };
     98 
     99 #endif //XCAM_CL_DEVICE_H
    100