forked from IntelPython/dpctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdpctl_sycl_extension_interface.cpp
More file actions
99 lines (88 loc) · 2.72 KB
/
dpctl_sycl_extension_interface.cpp
File metadata and controls
99 lines (88 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//===---- dpctl_sycl_extension_interface.cpp - Implements C API for SYCL ext =//
//
// Data Parallel Control (dpctl)
//
// Copyright 2020-2025 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file implements the data types and functions declared in
/// dpctl_sycl_extension_interface.h.
///
//===----------------------------------------------------------------------===//
#include "dpctl_sycl_extension_interface.h"
#include "dpctl_error_handlers.h"
#include "dpctl_sycl_type_casters.hpp"
#include <sycl/sycl.hpp>
using namespace dpctl::syclinterface;
DPCTL_API
__dpctl_give DPCTLSyclWorkGroupMemoryRef
DPCTLWorkGroupMemory_Create(size_t nbytes)
{
DPCTLSyclWorkGroupMemoryRef wgm = nullptr;
try {
auto WorkGroupMem = new RawWorkGroupMemory{nbytes};
wgm = wrap<RawWorkGroupMemory>(WorkGroupMem);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
}
return wgm;
}
DPCTL_API
void DPCTLWorkGroupMemory_Delete(__dpctl_take DPCTLSyclWorkGroupMemoryRef Ref)
{
delete unwrap<RawWorkGroupMemory>(Ref);
}
DPCTL_API
bool DPCTLWorkGroupMemory_Available()
{
#ifdef SYCL_EXT_ONEAPI_WORK_GROUP_MEMORY
return true;
#else
return false;
#endif
}
using raw_kernel_arg_t = std::vector<unsigned char>;
DPCTL_API
__dpctl_give DPCTLSyclRawKernelArgRef DPCTLRawKernelArg_Create(void *bytes,
size_t count)
{
DPCTLSyclRawKernelArgRef rka = nullptr;
try {
auto RawKernelArg =
std::unique_ptr<raw_kernel_arg_t>(new raw_kernel_arg_t(count));
std::memcpy(RawKernelArg->data(), bytes, count);
rka = wrap<raw_kernel_arg_t>(RawKernelArg.get());
RawKernelArg.release();
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
}
return rka;
}
DPCTL_API
void DPCTLRawKernelArg_Delete(__dpctl_take DPCTLSyclRawKernelArgRef Ref)
{
delete unwrap<raw_kernel_arg_t>(Ref);
}
DPCTL_API
bool DPCTLRawKernelArg_Available()
{
#ifdef SYCL_EXT_ONEAPI_RAW_KERNEL_ARG
return true;
#else
return false;
#endif
}