Home | History | Annotate | Download | only in ocl
      1 /*
      2  * cl_event.cpp - CL event
      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 #include "cl_event.h"
     22 
     23 namespace XCam {
     24 
     25 SmartPtr<CLEvent>  CLEvent::NullEvent;
     26 CLEventList CLEvent::EmptyList;
     27 
     28 CLEvent::CLEvent (cl_event event_id)
     29     : _event_id (event_id)
     30 {
     31 }
     32 
     33 CLEvent::~CLEvent ()
     34 {
     35     if (_event_id) {
     36         clReleaseEvent (_event_id);
     37     }
     38 }
     39 
     40 XCamReturn
     41 CLEvent::wait ()
     42 {
     43     cl_int error_code = CL_SUCCESS;
     44 
     45     XCAM_FAIL_RETURN (
     46         DEBUG,
     47         _event_id,
     48         XCAM_RETURN_ERROR_PARAM,
     49         "cl event wait failed, there's no event id");
     50 
     51     error_code = clWaitForEvents (1, &_event_id);
     52 
     53     XCAM_FAIL_RETURN (
     54         WARNING,
     55         error_code == CL_SUCCESS,
     56         XCAM_RETURN_ERROR_CL,
     57         "cl event wait failed with error cod:%d", error_code);
     58 
     59     return XCAM_RETURN_NO_ERROR;
     60 }
     61 
     62 bool
     63 CLEvent::get_cl_event_info (
     64     cl_event_info param_name, size_t param_size,
     65     void *param, size_t *param_size_ret)
     66 {
     67     cl_int error_code = CL_SUCCESS;
     68 
     69     XCAM_FAIL_RETURN (
     70         DEBUG,
     71         _event_id,
     72         false,
     73         "cl event wait failed, there's no event id");
     74 
     75     clGetEventInfo (_event_id, param_name, param_size, param, param_size_ret);
     76 
     77     XCAM_FAIL_RETURN(
     78         WARNING,
     79         error_code == CL_SUCCESS,
     80         false,
     81         "clGetEventInfo failed on param:%d, errno:%d", param_name, error_code);
     82     return true;
     83 }
     84 
     85 XCamReturn
     86 cl_events_wait (CLEventList &event_list)
     87 {
     88 #define XCAM_MAX_CL_EVENT_COUNT 256
     89 
     90     cl_event event_ids [XCAM_MAX_CL_EVENT_COUNT];
     91     uint32_t event_count = 0;
     92     cl_int error_code = CL_SUCCESS;
     93 
     94     if (event_list.empty ())
     95         return XCAM_RETURN_NO_ERROR;
     96 
     97     xcam_mem_clear (event_ids);
     98     for (CLEventList::iterator iter = event_list.begin ();
     99             iter != event_list.end (); ++iter) {
    100         SmartPtr<CLEvent> &event = *iter;
    101         XCAM_ASSERT (event->get_event_id ());
    102         event_ids[event_count++] = event->get_event_id ();
    103         if (event_count >= XCAM_MAX_CL_EVENT_COUNT)
    104             break;
    105     }
    106 
    107     XCAM_ASSERT (event_count > 0);
    108 
    109     error_code = clWaitForEvents (event_count, event_ids);
    110 
    111     XCAM_FAIL_RETURN (
    112         WARNING,
    113         error_code == CL_SUCCESS,
    114         XCAM_RETURN_ERROR_CL,
    115         "cl events wait failed with error cod:%d", error_code);
    116 
    117     return XCAM_RETURN_NO_ERROR;
    118 }
    119 
    120 };
    121