예제 #1
0
static void opencl_action_finalize(
  MTAPI_IN mtapi_action_hndl_t action,
  MTAPI_OUT mtapi_status_t* status
  ) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;
  cl_int err;
  EMBB_UNUSED_IN_RELEASE(err);

  if (embb_mtapi_node_is_initialized()) {
    embb_mtapi_node_t * node = embb_mtapi_node_get_instance();
    if (embb_mtapi_action_pool_is_handle_valid(node->action_pool, action)) {
      embb_mtapi_action_t * local_action =
        embb_mtapi_action_pool_get_storage_for_handle(
        node->action_pool, action);
      embb_mtapi_opencl_action_t * opencl_action =
        (embb_mtapi_opencl_action_t *)local_action->plugin_data;
      if (NULL != opencl_action->node_local_data) {
        err = clReleaseMemObject(opencl_action->node_local_data);
        assert(CL_SUCCESS == err);
      }

      err = clReleaseKernel(opencl_action->kernel);
      assert(CL_SUCCESS == err);
      err = clReleaseProgram(opencl_action->program);
      assert(CL_SUCCESS == err);

      embb_free(opencl_action);
      local_status = MTAPI_SUCCESS;
    }
  }

  mtapi_status_set(status, local_status);
}
예제 #2
0
void embb_mtapi_network_buffer_finalize(
  embb_mtapi_network_buffer_t * that) {
  that->position = 0;
  that->size = 0;
  that->capacity = 0;
  if (NULL != that->data) {
    embb_free(that->data);
    that->data = NULL;
  }
}
예제 #3
0
파일: thread.c 프로젝트: danklmn/embb
int embb_thread_join(embb_thread_t* thread, int *result_code) {
  int status = 0;
  status = pthread_join(thread->embb_internal_handle, NULL);
  if (result_code != NULL) {
    *result_code = thread->embb_internal_arg->result;
  }
  embb_free(thread->embb_internal_arg);
  if (status != 0) {
    return EMBB_ERROR;
  }
  return EMBB_SUCCESS;
}
예제 #4
0
파일: thread.c 프로젝트: danklmn/embb
int embb_thread_join(embb_thread_t* thread, int* result_code) {
  BOOL success;
  DWORD result;
  result = WaitForSingleObject(thread->embb_internal_handle, INFINITE);
  embb_free(thread->embb_internal_arg);
  if (result != WAIT_OBJECT_0) {
    /* WAIT_OBJECT_0 indicates successful waiting */
    return EMBB_ERROR;
  }
  if (result_code != NULL) { /* != NULL means the client wants a result code */
    if (GetExitCodeThread(thread->embb_internal_handle, &result) != 0) {
      *result_code = (int)result;
    } else {
      *result_code = 0; /* Error on obtaining result code */
      return EMBB_ERROR;
    }
  }
  success = CloseHandle(thread->embb_internal_handle);
  if (success == FALSE) {
    return EMBB_ERROR;
  }
  /*return embb_internal_thread_counter_try_decrement();*/
  return EMBB_SUCCESS;
}
예제 #5
0
mtapi_action_hndl_t mtapi_opencl_action_create(
  MTAPI_IN mtapi_job_id_t job_id,
  MTAPI_IN char* kernel_source,
  MTAPI_IN char* kernel_name,
  MTAPI_IN mtapi_size_t local_work_size,
  MTAPI_IN mtapi_size_t element_size,
  MTAPI_IN void* node_local_data,
  MTAPI_IN mtapi_size_t node_local_data_size,
  MTAPI_OUT mtapi_status_t* status) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;

  cl_int err;
  embb_mtapi_opencl_plugin_t * plugin = &embb_mtapi_opencl_plugin;
  embb_mtapi_opencl_action_t * action =
    (embb_mtapi_opencl_action_t*)embb_alloc(
      sizeof(embb_mtapi_opencl_action_t));
  mtapi_action_hndl_t action_hndl = { 0, 0 }; // invalid handle
  size_t kernel_length = strlen(kernel_source);
  mtapi_boolean_t free_program_on_error = MTAPI_FALSE;
  mtapi_boolean_t free_kernel_on_error = MTAPI_FALSE;
  mtapi_boolean_t free_node_local_data_on_error = MTAPI_FALSE;

  action->local_work_size = local_work_size;
  action->element_size = element_size;

  /* initialization */
  action->program = clCreateProgramWithSource(plugin->context,
    1, &kernel_source, &kernel_length, &err);
  if (CL_SUCCESS == err) {
    free_program_on_error = MTAPI_TRUE;
    err = clBuildProgram(action->program, 1, &plugin->device_id,
      NULL, NULL, NULL);
  } else {
    err = clGetProgramBuildInfo(action->program, plugin->device_id,
      CL_PROGRAM_BUILD_LOG, 1024, buffer, NULL);
  }

  if (CL_SUCCESS == err) {
    action->kernel = clCreateKernel(action->program, kernel_name, &err);
    if (CL_SUCCESS == err) {
      free_kernel_on_error = MTAPI_TRUE;
    }
  }

  if (0 < node_local_data_size) {
    action->node_local_data = clCreateBuffer(plugin->context, CL_MEM_READ_ONLY,
      node_local_data_size, NULL, &err);
    if (CL_SUCCESS == err) {
      free_node_local_data_on_error = MTAPI_TRUE;
    }
    action->node_local_data_size = (int)node_local_data_size;
    if (CL_SUCCESS == err) {
      err = clEnqueueWriteBuffer(plugin->command_queue,
        action->node_local_data, CL_TRUE, 0,
        (size_t)action->node_local_data_size, node_local_data, 0, NULL, NULL);
    }
  } else {
    action->node_local_data = NULL;
    action->node_local_data_size = 0;
  }

  if (CL_SUCCESS == err) {
    err = clSetKernelArg(action->kernel, 4, sizeof(cl_mem),
      (const void*)&action->node_local_data);
  }
  if (CL_SUCCESS == err) {
    err = clSetKernelArg(action->kernel, 5, sizeof(cl_int),
      (const void*)&action->node_local_data_size);
  }

  if (CL_SUCCESS == err) {
    action_hndl = mtapi_ext_plugin_action_create(
      job_id,
      opencl_task_start,
      opencl_task_cancel,
      opencl_action_finalize,
      action,
      node_local_data,
      node_local_data_size,
      MTAPI_NULL,
      &local_status);
  } else {
    if (free_node_local_data_on_error) {
      clReleaseMemObject(action->node_local_data);
    }
    if (free_kernel_on_error) {
      clReleaseKernel(action->kernel);
    }
    if (free_program_on_error) {
      clReleaseProgram(action->program);
    }
    embb_free(action);
  }

  mtapi_status_set(status, local_status);

  return action_hndl;
}
예제 #6
0
void embb_mtapi_alloc_deallocate(void * ptr) {
  if (ptr != NULL) {
    embb_free(ptr);
  }
}