Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
reframe360XL/Reframe360CLKernel.cpp at master · sctg-development/reframe360XL · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
sctg-development
reframe360XL
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
reframe360XL
/
Reframe360CLKernel.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
198 lines (158 loc) · 5.75 KB
master
Breadcrumbs
reframe360XL
/
Reframe360CLKernel.cpp
Copy path
Top
File metadata and controls
Code
Blame
198 lines (158 loc) · 5.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#
include
<
map
>
#
include
<
stdio.h
>
#
include
<
string
>
#
ifdef
_WIN64
#
include
<
Windows.h
>
#
else
#
include
<
pthread.h
>
#
endif
#
ifdef
__APPLE__
#
include
<
OpenCL/cl.h
>
#
else
#
include
<
CL/cl.h
>
#
endif
#
include
"
Reframe360CLKernel.h
"
#
include
"
KernelDebugHelper.h
"
#
define
MAX_SOURCE_SIZE
(
0x100000
)
void
CheckError
(cl_int p_Error,
const
char
* p_Msg)
{
if
(p_Error !=
CL_SUCCESS
)
{
fprintf
(stderr,
"
%s [%d]
\n
"
, p_Msg, p_Error);
}
}
class
Locker
{
public:
Locker
()
{
#
ifdef
_WIN64
InitializeCriticalSection
(&mutex);
#
else
pthread_mutex_init
(&mutex,
NULL
);
#
endif
}
~Locker
()
{
#
ifdef
_WIN64
DeleteCriticalSection
(&mutex);
#
else
pthread_mutex_destroy
(&mutex);
#
endif
}
void
Lock
()
{
#
ifdef
_WIN64
EnterCriticalSection
(&mutex);
#
else
pthread_mutex_lock
(&mutex);
#
endif
}
void
Unlock
()
{
#
ifdef
_WIN64
LeaveCriticalSection
(&mutex);
#
else
pthread_mutex_unlock
(&mutex);
#
endif
}
private:
#
ifdef
_WIN64
CRITICAL_SECTION
mutex;
#
else
pthread_mutex_t
mutex;
#
endif
};
#
ifdef
_WIN64
static
HMODULE
GetThisDllHandle
()
{
MEMORY_BASIC_INFORMATION
info;
size_t
len =
VirtualQueryEx
(
GetCurrentProcess
(), (
void
*)GetThisDllHandle, &info,
sizeof
(info));
return
len ? (
HMODULE
)info.
AllocationBase
:
NULL
;
}
#
endif
void
RunOpenCLKernel
(
void
* p_CmdQ,
int
p_inputFormat,
int
p_Width,
int
p_Height,
float
* p_Fov,
float
* p_Tinyplanet,
float
* p_Rectilinear,
const
float
* p_Input,
float
* p_Output,
float
* p_RotMat,
int
p_Samples,
bool
p_Bilinear)
{
cl_int error;
cl_command_queue cmdQ =
static_cast
<cl_command_queue>(p_CmdQ);
//
store device id and kernel per command queue (required for multi-GPU systems)
static
std::map<cl_command_queue, cl_device_id> deviceIdMap;
static
std::map<cl_command_queue, cl_kernel> kernelMap;
static
Locker locker;
//
simple lock to control access to the above maps from multiple threads
locker.
Lock
();
//
find the device id corresponding to the command queue
cl_device_id deviceId =
NULL
;
if
(deviceIdMap.
find
(cmdQ) == deviceIdMap.
end
())
{
error =
clGetCommandQueueInfo
(cmdQ,
CL_QUEUE_DEVICE
,
sizeof
(cl_device_id), &deviceId,
NULL
);
CheckError
(error,
"
Unable to get the device
"
);
deviceIdMap[cmdQ] = deviceId;
}
else
{
deviceId = deviceIdMap[cmdQ];
}
//
find the program kernel corresponding to the command queue
cl_kernel kernel;
cl_context clContext =
NULL
;
error =
clGetCommandQueueInfo
(cmdQ,
CL_QUEUE_CONTEXT
,
sizeof
(cl_context), &clContext,
NULL
);
CheckError
(error,
"
Unable to get the context
"
);
if
(kernelMap.
find
(cmdQ) == kernelMap.
end
())
{
cl_program program =
clCreateProgramWithSource
(clContext,
1
, (
const
char
**)&KernelSource,
NULL
, &error);
CheckError
(error,
"
Unable to create program
"
);
error =
clBuildProgram
(program,
0
,
NULL
,
NULL
,
NULL
,
NULL
);
CheckError
(error,
"
Unable to build program
"
);
if
(error ==
CL_BUILD_PROGRAM_FAILURE
) {
//
Determine the size of the log
size_t
log_size;
clGetProgramBuildInfo
(program, deviceId,
CL_PROGRAM_BUILD_LOG
,
0
,
NULL
, &log_size);
//
Allocate memory for the log
char
*log = (
char
*)
malloc
(log_size);
//
Get the log
clGetProgramBuildInfo
(program, deviceId,
CL_PROGRAM_BUILD_LOG
, log_size, log,
NULL
);
std::string
log_str
(log);
//
Print the log
printf
(
"
%s
\n
"
, log);
}
kernel =
clCreateKernel
(program,
"
Reframe360Kernel
"
, &error);
CheckError
(error,
"
Unable to create kernel
"
);
kernelMap[cmdQ] = kernel;
}
else
{
kernel = kernelMap[cmdQ];
}
int
bilinear
(p_Bilinear ?
1
:
0
);
ComputePrintDebugInformations
(
"
OpenCL
"
,p_inputFormat, p_Width, p_Height, p_Fov, p_Tinyplanet, p_Rectilinear, p_RotMat, p_Samples, p_Bilinear);
locker.
Unlock
();
int
count =
0
;
error =
clSetKernelArg
(kernel, count++,
sizeof
(
int
), &p_inputFormat);
error |=
clSetKernelArg
(kernel, count++,
sizeof
(
int
), &p_Width);
error |=
clSetKernelArg
(kernel, count++,
sizeof
(
int
), &p_Height);
cl_mem fov_buf =
clCreateBuffer
(clContext,
CL_MEM_READ_ONLY
|
CL_MEM_COPY_HOST_PTR
,
sizeof
(
float
)*p_Samples, p_Fov, &error);
cl_mem tinyplanet_buf =
clCreateBuffer
(clContext,
CL_MEM_READ_ONLY
|
CL_MEM_COPY_HOST_PTR
,
sizeof
(
float
)*p_Samples, p_Tinyplanet, &error);
cl_mem rectilinear_buf =
clCreateBuffer
(clContext,
CL_MEM_READ_ONLY
|
CL_MEM_COPY_HOST_PTR
,
sizeof
(
float
)*p_Samples, p_Rectilinear, &error);
error |=
clSetKernelArg
(kernel, count++,
sizeof
(cl_mem), &fov_buf);
error |=
clSetKernelArg
(kernel, count++,
sizeof
(cl_mem), &tinyplanet_buf);
error |=
clSetKernelArg
(kernel, count++,
sizeof
(cl_mem), &rectilinear_buf);
error |=
clSetKernelArg
(kernel, count++,
sizeof
(cl_mem), &p_Input);
error |=
clSetKernelArg
(kernel, count++,
sizeof
(cl_mem), &p_Output);
cl_mem rotmat_buf =
clCreateBuffer
(clContext,
CL_MEM_READ_ONLY
|
CL_MEM_COPY_HOST_PTR
,
sizeof
(
float
)*
9
*p_Samples, p_RotMat, &error);
error |=
clSetKernelArg
(kernel, count++,
sizeof
(cl_mem), &rotmat_buf);
error |=
clSetKernelArg
(kernel, count++,
sizeof
(
int
), &p_Samples);
error |=
clSetKernelArg
(kernel, count++,
sizeof
(
int
), &bilinear);
CheckError
(error,
"
Unable to set kernel arguments
"
);
size_t
localWorkSize[
2
], globalWorkSize[
2
];
clGetKernelWorkGroupInfo
(kernel, deviceId,
CL_KERNEL_WORK_GROUP_SIZE
,
sizeof
(
size_t
), localWorkSize,
NULL
);
localWorkSize[
1
] =
1
;
globalWorkSize[
0
] = ((p_Width + localWorkSize[
0
] -
1
) / localWorkSize[
0
]) * localWorkSize[
0
];
globalWorkSize[
1
] = p_Height;
cl_event clEvent;
clEnqueueNDRangeKernel
(cmdQ, kernel,
2
,
NULL
, globalWorkSize, localWorkSize,
0
,
NULL
, &clEvent);
clWaitForEvents
(
1
, &clEvent);
clReleaseMemObject
(fov_buf);
clReleaseMemObject
(tinyplanet_buf);
clReleaseMemObject
(rectilinear_buf);
clReleaseMemObject
(rotmat_buf);
}
You can’t perform that action at this time.