//===- Auto-generated file, part of the LLVM/Offload project --------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
static ol_error_struct_t UninitError = {
    OL_ERRC_UNINITIALIZED, "liboffload has not been initialized - please call "
                           "olInit before using this API"};
///////////////////////////////////////////////////////////////////////////////
llvm::Error olCalculateOptimalOccupancy_val(ol_device_handle_t Device,
                                            ol_symbol_handle_t Kernel,
                                            size_t SharedMemory,
                                            size_t *GroupSize) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Device) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Device");
    }

    if (NULL == Kernel) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Kernel");
    }

    if (NULL == GroupSize) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == GroupSize");
    }
  }

  return llvm::offload::olCalculateOptimalOccupancy_impl(
      Device, Kernel, SharedMemory, GroupSize);
}
OL_APIEXPORT ol_result_t OL_APICALL olCalculateOptimalOccupancy(
    ol_device_handle_t Device, ol_symbol_handle_t Kernel, size_t SharedMemory,
    size_t *GroupSize) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olCalculateOptimalOccupancy";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olCalculateOptimalOccupancy_val(Device, Kernel, SharedMemory, GroupSize));

  if (llvm::offload::isTracingEnabled()) {
    ol_calculate_optimal_occupancy_params_t Params = {
        &Device, &Kernel, &SharedMemory, &GroupSize};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olCalculateOptimalOccupancyWithCodeLoc(
    ol_device_handle_t Device, ol_symbol_handle_t Kernel, size_t SharedMemory,
    size_t *GroupSize, ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result =
      ::olCalculateOptimalOccupancy(Device, Kernel, SharedMemory, GroupSize);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olCreateEvent_val(ol_queue_handle_t Queue,
                              ol_event_handle_t *Event) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Queue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Queue");
    }

    if (NULL == Event) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Event");
    }
  }

  return llvm::offload::olCreateEvent_impl(Queue, Event);
}
OL_APIEXPORT ol_result_t OL_APICALL olCreateEvent(ol_queue_handle_t Queue,
                                                  ol_event_handle_t *Event) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olCreateEvent";
  }

  ol_result_t Result = llvmErrorToOffloadError(olCreateEvent_val(Queue, Event));

  if (llvm::offload::isTracingEnabled()) {
    ol_create_event_params_t Params = {&Queue, &Event};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olCreateEventWithCodeLoc(ol_queue_handle_t Queue,
                                     ol_event_handle_t *Event,
                                     ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olCreateEvent(Queue, Event);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olCreateProgram_val(ol_device_handle_t Device, const void *ProgData,
                                size_t ProgDataSize,
                                ol_program_handle_t *Program) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Device) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Device");
    }

    if (NULL == ProgData) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == ProgData");
    }

    if (NULL == Program) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Program");
    }
  }

  return llvm::offload::olCreateProgram_impl(Device, ProgData, ProgDataSize,
                                             Program);
}
OL_APIEXPORT ol_result_t OL_APICALL
olCreateProgram(ol_device_handle_t Device, const void *ProgData,
                size_t ProgDataSize, ol_program_handle_t *Program) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olCreateProgram";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olCreateProgram_val(Device, ProgData, ProgDataSize, Program));

  if (llvm::offload::isTracingEnabled()) {
    ol_create_program_params_t Params = {&Device, &ProgData, &ProgDataSize,
                                         &Program};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olCreateProgramWithCodeLoc(ol_device_handle_t Device,
                                       const void *ProgData,
                                       size_t ProgDataSize,
                                       ol_program_handle_t *Program,
                                       ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result =
      ::olCreateProgram(Device, ProgData, ProgDataSize, Program);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olCreateQueue_val(ol_device_handle_t Device,
                              ol_queue_handle_t *Queue) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Device) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Device");
    }

    if (NULL == Queue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Queue");
    }
  }

  return llvm::offload::olCreateQueue_impl(Device, Queue);
}
OL_APIEXPORT ol_result_t OL_APICALL olCreateQueue(ol_device_handle_t Device,
                                                  ol_queue_handle_t *Queue) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olCreateQueue";
  }

  ol_result_t Result =
      llvmErrorToOffloadError(olCreateQueue_val(Device, Queue));

  if (llvm::offload::isTracingEnabled()) {
    ol_create_queue_params_t Params = {&Device, &Queue};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olCreateQueueWithCodeLoc(ol_device_handle_t Device,
                                     ol_queue_handle_t *Queue,
                                     ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olCreateQueue(Device, Queue);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olDestroyEvent_val(ol_event_handle_t Event) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Event) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Event");
    }
  }

  return llvm::offload::olDestroyEvent_impl(Event);
}
OL_APIEXPORT ol_result_t OL_APICALL olDestroyEvent(ol_event_handle_t Event) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olDestroyEvent";
  }

  ol_result_t Result = llvmErrorToOffloadError(olDestroyEvent_val(Event));

  if (llvm::offload::isTracingEnabled()) {
    ol_destroy_event_params_t Params = {&Event};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olDestroyEventWithCodeLoc(ol_event_handle_t Event,
                                      ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olDestroyEvent(Event);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olDestroyProgram_val(ol_program_handle_t Program) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Program) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Program");
    }
  }

  return llvm::offload::olDestroyProgram_impl(Program);
}
OL_APIEXPORT ol_result_t OL_APICALL
olDestroyProgram(ol_program_handle_t Program) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olDestroyProgram";
  }

  ol_result_t Result = llvmErrorToOffloadError(olDestroyProgram_val(Program));

  if (llvm::offload::isTracingEnabled()) {
    ol_destroy_program_params_t Params = {&Program};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olDestroyProgramWithCodeLoc(ol_program_handle_t Program,
                                        ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olDestroyProgram(Program);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olDestroyQueue_val(ol_queue_handle_t Queue) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Queue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Queue");
    }
  }

  return llvm::offload::olDestroyQueue_impl(Queue);
}
OL_APIEXPORT ol_result_t OL_APICALL olDestroyQueue(ol_queue_handle_t Queue) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olDestroyQueue";
  }

  ol_result_t Result = llvmErrorToOffloadError(olDestroyQueue_val(Queue));

  if (llvm::offload::isTracingEnabled()) {
    ol_destroy_queue_params_t Params = {&Queue};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olDestroyQueueWithCodeLoc(ol_queue_handle_t Queue,
                                      ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olDestroyQueue(Queue);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetDeviceInfo_val(ol_device_handle_t Device,
                                ol_device_info_t PropName, size_t PropSize,
                                void *PropValue) {
  if (llvm::offload::isValidationEnabled()) {
    if (PropSize == 0) {
      return createOffloadError(error::ErrorCode::INVALID_SIZE,
                                "validation failure: PropSize == 0");
    }

    if (NULL == Device) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Device");
    }

    if (NULL == PropValue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropValue");
    }
  }

  return llvm::offload::olGetDeviceInfo_impl(Device, PropName, PropSize,
                                             PropValue);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfo(ol_device_handle_t Device,
                                                    ol_device_info_t PropName,
                                                    size_t PropSize,
                                                    void *PropValue) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetDeviceInfo";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetDeviceInfo_val(Device, PropName, PropSize, PropValue));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_device_info_params_t Params = {&Device, &PropName, &PropSize,
                                          &PropValue};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetDeviceInfoWithCodeLoc(ol_device_handle_t Device,
                                       ol_device_info_t PropName,
                                       size_t PropSize, void *PropValue,
                                       ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetDeviceInfo(Device, PropName, PropSize, PropValue);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetDeviceInfoSize_val(ol_device_handle_t Device,
                                    ol_device_info_t PropName,
                                    size_t *PropSizeRet) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Device) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Device");
    }

    if (NULL == PropSizeRet) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropSizeRet");
    }
  }

  return llvm::offload::olGetDeviceInfoSize_impl(Device, PropName, PropSizeRet);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfoSize(
    ol_device_handle_t Device, ol_device_info_t PropName, size_t *PropSizeRet) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetDeviceInfoSize";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetDeviceInfoSize_val(Device, PropName, PropSizeRet));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_device_info_size_params_t Params = {&Device, &PropName,
                                               &PropSizeRet};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetDeviceInfoSizeWithCodeLoc(ol_device_handle_t Device,
                                           ol_device_info_t PropName,
                                           size_t *PropSizeRet,
                                           ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetDeviceInfoSize(Device, PropName, PropSizeRet);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetEventInfo_val(ol_event_handle_t Event,
                               ol_event_info_t PropName, size_t PropSize,
                               void *PropValue) {
  if (llvm::offload::isValidationEnabled()) {
    if (PropSize == 0) {
      return createOffloadError(error::ErrorCode::INVALID_SIZE,
                                "validation failure: PropSize == 0");
    }

    if (NULL == Event) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Event");
    }

    if (NULL == PropValue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropValue");
    }
  }

  return llvm::offload::olGetEventInfo_impl(Event, PropName, PropSize,
                                            PropValue);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetEventInfo(ol_event_handle_t Event,
                                                   ol_event_info_t PropName,
                                                   size_t PropSize,
                                                   void *PropValue) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetEventInfo";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetEventInfo_val(Event, PropName, PropSize, PropValue));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_event_info_params_t Params = {&Event, &PropName, &PropSize,
                                         &PropValue};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetEventInfoWithCodeLoc(ol_event_handle_t Event,
                                      ol_event_info_t PropName, size_t PropSize,
                                      void *PropValue,
                                      ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetEventInfo(Event, PropName, PropSize, PropValue);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetEventInfoSize_val(ol_event_handle_t Event,
                                   ol_event_info_t PropName,
                                   size_t *PropSizeRet) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Event) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Event");
    }

    if (NULL == PropSizeRet) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropSizeRet");
    }
  }

  return llvm::offload::olGetEventInfoSize_impl(Event, PropName, PropSizeRet);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetEventInfoSize(ol_event_handle_t Event,
                                                       ol_event_info_t PropName,
                                                       size_t *PropSizeRet) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetEventInfoSize";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetEventInfoSize_val(Event, PropName, PropSizeRet));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_event_info_size_params_t Params = {&Event, &PropName, &PropSizeRet};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetEventInfoSizeWithCodeLoc(ol_event_handle_t Event,
                                          ol_event_info_t PropName,
                                          size_t *PropSizeRet,
                                          ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetEventInfoSize(Event, PropName, PropSizeRet);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetMemInfo_val(const void *Ptr, ol_mem_info_t PropName,
                             size_t PropSize, void *PropValue) {
  if (llvm::offload::isValidationEnabled()) {
    if (PropSize == 0) {
      return createOffloadError(error::ErrorCode::INVALID_SIZE,
                                "validation failure: PropSize == 0");
    }

    if (NULL == Ptr) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Ptr");
    }

    if (NULL == PropValue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropValue");
    }
  }

  return llvm::offload::olGetMemInfo_impl(Ptr, PropName, PropSize, PropValue);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetMemInfo(const void *Ptr,
                                                 ol_mem_info_t PropName,
                                                 size_t PropSize,
                                                 void *PropValue) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetMemInfo";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetMemInfo_val(Ptr, PropName, PropSize, PropValue));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_mem_info_params_t Params = {&Ptr, &PropName, &PropSize, &PropValue};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetMemInfoWithCodeLoc(const void *Ptr, ol_mem_info_t PropName,
                                    size_t PropSize, void *PropValue,
                                    ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetMemInfo(Ptr, PropName, PropSize, PropValue);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetMemInfoSize_val(const void *Ptr, ol_mem_info_t PropName,
                                 size_t *PropSizeRet) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Ptr) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Ptr");
    }

    if (NULL == PropSizeRet) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropSizeRet");
    }
  }

  return llvm::offload::olGetMemInfoSize_impl(Ptr, PropName, PropSizeRet);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetMemInfoSize(const void *Ptr,
                                                     ol_mem_info_t PropName,
                                                     size_t *PropSizeRet) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetMemInfoSize";
  }

  ol_result_t Result =
      llvmErrorToOffloadError(olGetMemInfoSize_val(Ptr, PropName, PropSizeRet));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_mem_info_size_params_t Params = {&Ptr, &PropName, &PropSizeRet};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetMemInfoSizeWithCodeLoc(const void *Ptr, ol_mem_info_t PropName,
                                        size_t *PropSizeRet,
                                        ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetMemInfoSize(Ptr, PropName, PropSizeRet);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetPlatformInfo_val(ol_platform_handle_t Platform,
                                  ol_platform_info_t PropName, size_t PropSize,
                                  void *PropValue) {
  if (llvm::offload::isValidationEnabled()) {
    if (PropSize == 0) {
      return createOffloadError(error::ErrorCode::INVALID_SIZE,
                                "validation failure: PropSize == 0");
    }

    if (NULL == Platform) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Platform");
    }

    if (NULL == PropValue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropValue");
    }
  }

  return llvm::offload::olGetPlatformInfo_impl(Platform, PropName, PropSize,
                                               PropValue);
}
OL_APIEXPORT ol_result_t OL_APICALL
olGetPlatformInfo(ol_platform_handle_t Platform, ol_platform_info_t PropName,
                  size_t PropSize, void *PropValue) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetPlatformInfo";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetPlatformInfo_val(Platform, PropName, PropSize, PropValue));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_platform_info_params_t Params = {&Platform, &PropName, &PropSize,
                                            &PropValue};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetPlatformInfoWithCodeLoc(ol_platform_handle_t Platform,
                                         ol_platform_info_t PropName,
                                         size_t PropSize, void *PropValue,
                                         ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result =
      ::olGetPlatformInfo(Platform, PropName, PropSize, PropValue);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetPlatformInfoSize_val(ol_platform_handle_t Platform,
                                      ol_platform_info_t PropName,
                                      size_t *PropSizeRet) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Platform) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Platform");
    }

    if (NULL == PropSizeRet) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropSizeRet");
    }
  }

  return llvm::offload::olGetPlatformInfoSize_impl(Platform, PropName,
                                                   PropSizeRet);
}
OL_APIEXPORT ol_result_t OL_APICALL
olGetPlatformInfoSize(ol_platform_handle_t Platform,
                      ol_platform_info_t PropName, size_t *PropSizeRet) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetPlatformInfoSize";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetPlatformInfoSize_val(Platform, PropName, PropSizeRet));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_platform_info_size_params_t Params = {&Platform, &PropName,
                                                 &PropSizeRet};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetPlatformInfoSizeWithCodeLoc(ol_platform_handle_t Platform,
                                             ol_platform_info_t PropName,
                                             size_t *PropSizeRet,
                                             ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetPlatformInfoSize(Platform, PropName, PropSizeRet);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetQueueInfo_val(ol_queue_handle_t Queue,
                               ol_queue_info_t PropName, size_t PropSize,
                               void *PropValue) {
  if (llvm::offload::isValidationEnabled()) {
    if (PropSize == 0) {
      return createOffloadError(error::ErrorCode::INVALID_SIZE,
                                "validation failure: PropSize == 0");
    }

    if (NULL == Queue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Queue");
    }

    if (NULL == PropValue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropValue");
    }
  }

  return llvm::offload::olGetQueueInfo_impl(Queue, PropName, PropSize,
                                            PropValue);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetQueueInfo(ol_queue_handle_t Queue,
                                                   ol_queue_info_t PropName,
                                                   size_t PropSize,
                                                   void *PropValue) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetQueueInfo";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetQueueInfo_val(Queue, PropName, PropSize, PropValue));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_queue_info_params_t Params = {&Queue, &PropName, &PropSize,
                                         &PropValue};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetQueueInfoWithCodeLoc(ol_queue_handle_t Queue,
                                      ol_queue_info_t PropName, size_t PropSize,
                                      void *PropValue,
                                      ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetQueueInfo(Queue, PropName, PropSize, PropValue);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetQueueInfoSize_val(ol_queue_handle_t Queue,
                                   ol_queue_info_t PropName,
                                   size_t *PropSizeRet) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Queue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Queue");
    }

    if (NULL == PropSizeRet) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropSizeRet");
    }
  }

  return llvm::offload::olGetQueueInfoSize_impl(Queue, PropName, PropSizeRet);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetQueueInfoSize(ol_queue_handle_t Queue,
                                                       ol_queue_info_t PropName,
                                                       size_t *PropSizeRet) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetQueueInfoSize";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetQueueInfoSize_val(Queue, PropName, PropSizeRet));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_queue_info_size_params_t Params = {&Queue, &PropName, &PropSizeRet};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetQueueInfoSizeWithCodeLoc(ol_queue_handle_t Queue,
                                          ol_queue_info_t PropName,
                                          size_t *PropSizeRet,
                                          ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetQueueInfoSize(Queue, PropName, PropSizeRet);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetSymbol_val(ol_program_handle_t Program, const char *Name,
                            ol_symbol_kind_t Kind, ol_symbol_handle_t *Symbol) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Program) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Program");
    }

    if (NULL == Name) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Name");
    }

    if (NULL == Symbol) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Symbol");
    }
  }

  return llvm::offload::olGetSymbol_impl(Program, Name, Kind, Symbol);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetSymbol(ol_program_handle_t Program,
                                                const char *Name,
                                                ol_symbol_kind_t Kind,
                                                ol_symbol_handle_t *Symbol) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetSymbol";
  }

  ol_result_t Result =
      llvmErrorToOffloadError(olGetSymbol_val(Program, Name, Kind, Symbol));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_symbol_params_t Params = {&Program, &Name, &Kind, &Symbol};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetSymbolWithCodeLoc(ol_program_handle_t Program,
                                   const char *Name, ol_symbol_kind_t Kind,
                                   ol_symbol_handle_t *Symbol,
                                   ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetSymbol(Program, Name, Kind, Symbol);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetSymbolInfo_val(ol_symbol_handle_t Symbol,
                                ol_symbol_info_t PropName, size_t PropSize,
                                void *PropValue) {
  if (llvm::offload::isValidationEnabled()) {
    if (PropSize == 0) {
      return createOffloadError(error::ErrorCode::INVALID_SIZE,
                                "validation failure: PropSize == 0");
    }

    if (NULL == Symbol) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Symbol");
    }

    if (NULL == PropValue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropValue");
    }
  }

  return llvm::offload::olGetSymbolInfo_impl(Symbol, PropName, PropSize,
                                             PropValue);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetSymbolInfo(ol_symbol_handle_t Symbol,
                                                    ol_symbol_info_t PropName,
                                                    size_t PropSize,
                                                    void *PropValue) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetSymbolInfo";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetSymbolInfo_val(Symbol, PropName, PropSize, PropValue));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_symbol_info_params_t Params = {&Symbol, &PropName, &PropSize,
                                          &PropValue};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetSymbolInfoWithCodeLoc(ol_symbol_handle_t Symbol,
                                       ol_symbol_info_t PropName,
                                       size_t PropSize, void *PropValue,
                                       ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetSymbolInfo(Symbol, PropName, PropSize, PropValue);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetSymbolInfoSize_val(ol_symbol_handle_t Symbol,
                                    ol_symbol_info_t PropName,
                                    size_t *PropSizeRet) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Symbol) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Symbol");
    }

    if (NULL == PropSizeRet) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PropSizeRet");
    }
  }

  return llvm::offload::olGetSymbolInfoSize_impl(Symbol, PropName, PropSizeRet);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetSymbolInfoSize(
    ol_symbol_handle_t Symbol, ol_symbol_info_t PropName, size_t *PropSizeRet) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olGetSymbolInfoSize";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olGetSymbolInfoSize_val(Symbol, PropName, PropSizeRet));

  if (llvm::offload::isTracingEnabled()) {
    ol_get_symbol_info_size_params_t Params = {&Symbol, &PropName,
                                               &PropSizeRet};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olGetSymbolInfoSizeWithCodeLoc(ol_symbol_handle_t Symbol,
                                           ol_symbol_info_t PropName,
                                           size_t *PropSizeRet,
                                           ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olGetSymbolInfoSize(Symbol, PropName, PropSizeRet);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olInit_val() { return llvm::offload::olInit_impl(); }
OL_APIEXPORT ol_result_t OL_APICALL olInit() {
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olInit";
  }

  ol_result_t Result = llvmErrorToOffloadError(olInit_val());

  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "()";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olInitWithCodeLoc(ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olInit();

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olIsValidBinary_val(ol_device_handle_t Device, const void *ProgData,
                                size_t ProgDataSize, bool *Valid) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Device) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Device");
    }

    if (NULL == ProgData) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == ProgData");
    }

    if (NULL == Valid) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Valid");
    }
  }

  return llvm::offload::olIsValidBinary_impl(Device, ProgData, ProgDataSize,
                                             Valid);
}
OL_APIEXPORT ol_result_t OL_APICALL olIsValidBinary(ol_device_handle_t Device,
                                                    const void *ProgData,
                                                    size_t ProgDataSize,
                                                    bool *Valid) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olIsValidBinary";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olIsValidBinary_val(Device, ProgData, ProgDataSize, Valid));

  if (llvm::offload::isTracingEnabled()) {
    ol_is_valid_binary_params_t Params = {&Device, &ProgData, &ProgDataSize,
                                          &Valid};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olIsValidBinaryWithCodeLoc(ol_device_handle_t Device,
                                       const void *ProgData,
                                       size_t ProgDataSize, bool *Valid,
                                       ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olIsValidBinary(Device, ProgData, ProgDataSize, Valid);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olIterateDevices_val(ol_device_iterate_cb_t Callback,
                                 void *UserData) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Callback) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Callback");
    }
  }

  return llvm::offload::olIterateDevices_impl(Callback, UserData);
}
OL_APIEXPORT ol_result_t OL_APICALL
olIterateDevices(ol_device_iterate_cb_t Callback, void *UserData) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olIterateDevices";
  }

  ol_result_t Result =
      llvmErrorToOffloadError(olIterateDevices_val(Callback, UserData));

  if (llvm::offload::isTracingEnabled()) {
    ol_iterate_devices_params_t Params = {&Callback, &UserData};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olIterateDevicesWithCodeLoc(ol_device_iterate_cb_t Callback,
                                        void *UserData,
                                        ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olIterateDevices(Callback, UserData);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olLaunchHostFunction_val(ol_queue_handle_t Queue,
                                     ol_host_function_cb_t Callback,
                                     void *UserData) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Queue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Queue");
    }

    if (NULL == Callback) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Callback");
    }
  }

  return llvm::offload::olLaunchHostFunction_impl(Queue, Callback, UserData);
}
OL_APIEXPORT ol_result_t OL_APICALL olLaunchHostFunction(
    ol_queue_handle_t Queue, ol_host_function_cb_t Callback, void *UserData) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olLaunchHostFunction";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olLaunchHostFunction_val(Queue, Callback, UserData));

  if (llvm::offload::isTracingEnabled()) {
    ol_launch_host_function_params_t Params = {&Queue, &Callback, &UserData};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olLaunchHostFunctionWithCodeLoc(ol_queue_handle_t Queue,
                                            ol_host_function_cb_t Callback,
                                            void *UserData,
                                            ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olLaunchHostFunction(Queue, Callback, UserData);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error
olLaunchKernel_val(ol_queue_handle_t Queue, ol_device_handle_t Device,
                   ol_symbol_handle_t Kernel, const void *ArgumentsData,
                   size_t ArgumentsSize,
                   const ol_kernel_launch_size_args_t *LaunchSizeArgs) {
  if (llvm::offload::isValidationEnabled()) {
    if (ArgumentsSize > 0 && ArgumentsData == NULL) {
      return createOffloadError(
          error::ErrorCode::INVALID_ARGUMENT,
          "validation failure: ArgumentsSize > 0 && ArgumentsData == NULL");
    }

    if (NULL == Device) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Device");
    }

    if (NULL == Kernel) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Kernel");
    }

    if (NULL == LaunchSizeArgs) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == LaunchSizeArgs");
    }
  }

  return llvm::offload::olLaunchKernel_impl(
      Queue, Device, Kernel, ArgumentsData, ArgumentsSize, LaunchSizeArgs);
}
OL_APIEXPORT ol_result_t OL_APICALL olLaunchKernel(
    ol_queue_handle_t Queue, ol_device_handle_t Device,
    ol_symbol_handle_t Kernel, const void *ArgumentsData, size_t ArgumentsSize,
    const ol_kernel_launch_size_args_t *LaunchSizeArgs) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olLaunchKernel";
  }

  ol_result_t Result = llvmErrorToOffloadError(olLaunchKernel_val(
      Queue, Device, Kernel, ArgumentsData, ArgumentsSize, LaunchSizeArgs));

  if (llvm::offload::isTracingEnabled()) {
    ol_launch_kernel_params_t Params = {&Queue,         &Device,
                                        &Kernel,        &ArgumentsData,
                                        &ArgumentsSize, &LaunchSizeArgs};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t
olLaunchKernelWithCodeLoc(ol_queue_handle_t Queue, ol_device_handle_t Device,
                          ol_symbol_handle_t Kernel, const void *ArgumentsData,
                          size_t ArgumentsSize,
                          const ol_kernel_launch_size_args_t *LaunchSizeArgs,
                          ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olLaunchKernel(Queue, Device, Kernel, ArgumentsData,
                                        ArgumentsSize, LaunchSizeArgs);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olMemAlloc_val(ol_device_handle_t Device, ol_alloc_type_t Type,
                           size_t Size, void **AllocationOut) {
  if (llvm::offload::isValidationEnabled()) {
    if (Size == 0) {
      return createOffloadError(error::ErrorCode::INVALID_SIZE,
                                "validation failure: Size == 0");
    }

    if (NULL == Device) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Device");
    }

    if (NULL == AllocationOut) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == AllocationOut");
    }
  }

  return llvm::offload::olMemAlloc_impl(Device, Type, Size, AllocationOut);
}
OL_APIEXPORT ol_result_t OL_APICALL olMemAlloc(ol_device_handle_t Device,
                                               ol_alloc_type_t Type,
                                               size_t Size,
                                               void **AllocationOut) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olMemAlloc";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olMemAlloc_val(Device, Type, Size, AllocationOut));

  if (llvm::offload::isTracingEnabled()) {
    ol_mem_alloc_params_t Params = {&Device, &Type, &Size, &AllocationOut};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olMemAllocWithCodeLoc(ol_device_handle_t Device,
                                  ol_alloc_type_t Type, size_t Size,
                                  void **AllocationOut,
                                  ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olMemAlloc(Device, Type, Size, AllocationOut);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olMemFill_val(ol_queue_handle_t Queue, void *Ptr,
                          size_t PatternSize, const void *PatternPtr,
                          size_t FillSize) {
  if (llvm::offload::isValidationEnabled()) {
    if (FillSize % PatternSize != 0) {
      return createOffloadError(
          error::ErrorCode::INVALID_SIZE,
          "validation failure: FillSize % PatternSize != 0");
    }

    if (NULL == Ptr) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Ptr");
    }

    if (NULL == PatternPtr) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == PatternPtr");
    }
  }

  return llvm::offload::olMemFill_impl(Queue, Ptr, PatternSize, PatternPtr,
                                       FillSize);
}
OL_APIEXPORT ol_result_t OL_APICALL olMemFill(ol_queue_handle_t Queue,
                                              void *Ptr, size_t PatternSize,
                                              const void *PatternPtr,
                                              size_t FillSize) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olMemFill";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olMemFill_val(Queue, Ptr, PatternSize, PatternPtr, FillSize));

  if (llvm::offload::isTracingEnabled()) {
    ol_mem_fill_params_t Params = {&Queue, &Ptr, &PatternSize, &PatternPtr,
                                   &FillSize};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olMemFillWithCodeLoc(ol_queue_handle_t Queue, void *Ptr,
                                 size_t PatternSize, const void *PatternPtr,
                                 size_t FillSize,
                                 ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result =
      ::olMemFill(Queue, Ptr, PatternSize, PatternPtr, FillSize);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olMemFree_val(void *Address) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Address) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Address");
    }
  }

  return llvm::offload::olMemFree_impl(Address);
}
OL_APIEXPORT ol_result_t OL_APICALL olMemFree(void *Address) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olMemFree";
  }

  ol_result_t Result = llvmErrorToOffloadError(olMemFree_val(Address));

  if (llvm::offload::isTracingEnabled()) {
    ol_mem_free_params_t Params = {&Address};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olMemFreeWithCodeLoc(void *Address,
                                 ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olMemFree(Address);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olMemcpy_val(ol_queue_handle_t Queue, void *DstPtr,
                         ol_device_handle_t DstDevice, const void *SrcPtr,
                         ol_device_handle_t SrcDevice, size_t Size) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == DstDevice) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == DstDevice");
    }

    if (NULL == SrcDevice) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == SrcDevice");
    }

    if (NULL == DstPtr) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == DstPtr");
    }

    if (NULL == SrcPtr) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == SrcPtr");
    }
  }

  return llvm::offload::olMemcpy_impl(Queue, DstPtr, DstDevice, SrcPtr,
                                      SrcDevice, Size);
}
OL_APIEXPORT ol_result_t OL_APICALL
olMemcpy(ol_queue_handle_t Queue, void *DstPtr, ol_device_handle_t DstDevice,
         const void *SrcPtr, ol_device_handle_t SrcDevice, size_t Size) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olMemcpy";
  }

  ol_result_t Result = llvmErrorToOffloadError(
      olMemcpy_val(Queue, DstPtr, DstDevice, SrcPtr, SrcDevice, Size));

  if (llvm::offload::isTracingEnabled()) {
    ol_memcpy_params_t Params = {&Queue,  &DstPtr,    &DstDevice,
                                 &SrcPtr, &SrcDevice, &Size};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olMemcpyWithCodeLoc(ol_queue_handle_t Queue, void *DstPtr,
                                ol_device_handle_t DstDevice,
                                const void *SrcPtr,
                                ol_device_handle_t SrcDevice, size_t Size,
                                ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result =
      ::olMemcpy(Queue, DstPtr, DstDevice, SrcPtr, SrcDevice, Size);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olShutDown_val() { return llvm::offload::olShutDown_impl(); }
OL_APIEXPORT ol_result_t OL_APICALL olShutDown() {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olShutDown";
  }

  ol_result_t Result = llvmErrorToOffloadError(olShutDown_val());

  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "()";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olShutDownWithCodeLoc(ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olShutDown();

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olSyncEvent_val(ol_event_handle_t Event) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Event) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Event");
    }
  }

  return llvm::offload::olSyncEvent_impl(Event);
}
OL_APIEXPORT ol_result_t OL_APICALL olSyncEvent(ol_event_handle_t Event) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olSyncEvent";
  }

  ol_result_t Result = llvmErrorToOffloadError(olSyncEvent_val(Event));

  if (llvm::offload::isTracingEnabled()) {
    ol_sync_event_params_t Params = {&Event};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olSyncEventWithCodeLoc(ol_event_handle_t Event,
                                   ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olSyncEvent(Event);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olSyncQueue_val(ol_queue_handle_t Queue) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Queue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Queue");
    }
  }

  return llvm::offload::olSyncQueue_impl(Queue);
}
OL_APIEXPORT ol_result_t OL_APICALL olSyncQueue(ol_queue_handle_t Queue) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olSyncQueue";
  }

  ol_result_t Result = llvmErrorToOffloadError(olSyncQueue_val(Queue));

  if (llvm::offload::isTracingEnabled()) {
    ol_sync_queue_params_t Params = {&Queue};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olSyncQueueWithCodeLoc(ol_queue_handle_t Queue,
                                   ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olSyncQueue(Queue);

  currentCodeLocation() = nullptr;
  return Result;
}

///////////////////////////////////////////////////////////////////////////////
llvm::Error olWaitEvents_val(ol_queue_handle_t Queue, ol_event_handle_t *Events,
                             size_t NumEvents) {
  if (llvm::offload::isValidationEnabled()) {
    if (NULL == Queue) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
                                "validation failure: NULL == Queue");
    }

    if (NULL == Events) {
      return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
                                "validation failure: NULL == Events");
    }
  }

  return llvm::offload::olWaitEvents_impl(Queue, Events, NumEvents);
}
OL_APIEXPORT ol_result_t OL_APICALL olWaitEvents(ol_queue_handle_t Queue,
                                                 ol_event_handle_t *Events,
                                                 size_t NumEvents) {
  if (!llvm::offload::isOffloadInitialized())
    return &UninitError;
  if (llvm::offload::isTracingEnabled()) {
    llvm::errs() << "---> olWaitEvents";
  }

  ol_result_t Result =
      llvmErrorToOffloadError(olWaitEvents_val(Queue, Events, NumEvents));

  if (llvm::offload::isTracingEnabled()) {
    ol_wait_events_params_t Params = {&Queue, &Events, &NumEvents};
    llvm::errs() << "(" << &Params << ")";
    llvm::errs() << "-> " << Result << "\n";
    if (Result && Result->Details) {
      llvm::errs() << "     *Error Details* " << Result->Details << " \n";
    }
  }
  return Result;
}
ol_result_t olWaitEventsWithCodeLoc(ol_queue_handle_t Queue,
                                    ol_event_handle_t *Events, size_t NumEvents,
                                    ol_code_location_t *CodeLocation) {
  currentCodeLocation() = CodeLocation;
  ol_result_t Result = ::olWaitEvents(Queue, Events, NumEvents);

  currentCodeLocation() = nullptr;
  return Result;
}
