-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cf7e2f
commit adb6b3d
Showing
8 changed files
with
142 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===--------- kernel.hpp - OpenCL Adapter ---------------------------===// | ||
// | ||
// Copyright (C) 2023 Intel Corporation | ||
// | ||
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM | ||
// Exceptions. See LICENSE.TXT | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#pragma once | ||
|
||
#include "common.hpp" | ||
#include "context.hpp" | ||
|
||
#include <vector> | ||
|
||
struct ur_kernel_handle_t_ { | ||
using native_type = cl_kernel; | ||
native_type Kernel; | ||
ur_program_handle_t Program; | ||
ur_context_handle_t Context; | ||
|
||
ur_kernel_handle_t_(native_type Kernel, ur_program_handle_t Program, | ||
ur_context_handle_t Context) | ||
: Kernel(Kernel), Program(Program), Context(Context) {} | ||
|
||
~ur_kernel_handle_t_() {} | ||
|
||
ur_result_t initWithNative() { | ||
if (!Program) { | ||
cl_program CLProgram; | ||
CL_RETURN_ON_FAILURE(clGetKernelInfo( | ||
Kernel, CL_KERNEL_PROGRAM, sizeof(CLProgram), &CLProgram, nullptr)); | ||
ur_native_handle_t NativeProgram = | ||
reinterpret_cast<ur_native_handle_t>(CLProgram); | ||
UR_RETURN_ON_FAILURE(urProgramCreateWithNativeHandle( | ||
NativeProgram, nullptr, nullptr, &Program)); | ||
} | ||
cl_context CLContext; | ||
CL_RETURN_ON_FAILURE(clGetKernelInfo( | ||
Kernel, CL_KERNEL_CONTEXT, sizeof(CLContext), &CLContext, nullptr)); | ||
if (!Context) { | ||
ur_native_handle_t NativeContext = | ||
reinterpret_cast<ur_native_handle_t>(CLContext); | ||
UR_RETURN_ON_FAILURE(urContextCreateWithNativeHandle( | ||
NativeContext, 0, nullptr, nullptr, &Context)); | ||
} else if (Context->get() != CLContext) { | ||
return UR_RESULT_ERROR_INVALID_CONTEXT; | ||
} | ||
return UR_RESULT_SUCCESS; | ||
} | ||
|
||
native_type get() { return Kernel; } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.