Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
docking
ocladock
Commits
284b564b
Commit
284b564b
authored
May 14, 2018
by
lvs
Browse files
optimized ocl program building
parent
be11e258
Changes
5
Hide whitespace changes
Inline
Side-by-side
host/src/performdocking.cpp
View file @
284b564b
...
...
@@ -116,10 +116,11 @@ filled with clock() */
// =======================================================================
// OpenCL Host Setup
// =======================================================================
cl_platform_id
*
platform_id
;
cl_device_id
*
device_id
;
cl_context
context
;
cl_platform_id
*
platform_id
;
cl_device_id
*
device_id
;
cl_context
context
;
cl_command_queue
command_queue
;
cl_program
program
;
#ifdef _WIN32
const
char
*
filename
=
KRNL_FILE
;
...
...
@@ -166,7 +167,7 @@ filled with clock() */
// Create command queue for first device
if
(
createCommandQueue
(
context
,
device_id
[
0
],
&
command_queue
)
!=
0
)
return
1
;
// Create program
and kernel
from source
// Create program from source
#ifdef _WIN32
if
(
ImportSource
(
filename
,
name_k1
,
device_id
,
context
,
options_program
,
&
kernel1
)
!=
0
)
return
1
;
if
(
ImportSource
(
filename
,
name_k2
,
device_id
,
context
,
options_program
,
&
kernel2
)
!=
0
)
return
1
;
...
...
@@ -174,13 +175,16 @@ filled with clock() */
if
(
ImportSource
(
filename
,
name_k4
,
device_id
,
context
,
options_program
,
&
kernel4
)
!=
0
)
return
1
;
if
(
ImportSource
(
filename
,
name_k5
,
device_id
,
context
,
options_program
,
&
kernel5
)
!=
0
)
return
1
;
#else
if
(
ImportSource
(
calcenergy_ocl
,
name_k1
,
device_id
,
context
,
options_program
,
&
kernel1
)
!=
0
)
return
1
;
if
(
ImportSource
(
calcenergy_ocl
,
name_k2
,
device_id
,
context
,
options_program
,
&
kernel2
)
!=
0
)
return
1
;
if
(
ImportSource
(
calcenergy_ocl
,
name_k3
,
device_id
,
context
,
options_program
,
&
kernel3
)
!=
0
)
return
1
;
if
(
ImportSource
(
calcenergy_ocl
,
name_k4
,
device_id
,
context
,
options_program
,
&
kernel4
)
!=
0
)
return
1
;
if
(
ImportSource
(
calcenergy_ocl
,
name_k5
,
device_id
,
context
,
options_program
,
&
kernel5
)
!=
0
)
return
1
;
if
(
ImportSourceToProgram
(
calcenergy_ocl
,
device_id
,
context
,
&
program
,
options_program
)
!=
0
)
return
1
;
#endif
// Create kernels
if
(
createKernel
(
device_id
,
&
program
,
name_k1
,
&
kernel1
)
!=
0
)
return
1
;
if
(
createKernel
(
device_id
,
&
program
,
name_k2
,
&
kernel2
)
!=
0
)
return
1
;
if
(
createKernel
(
device_id
,
&
program
,
name_k3
,
&
kernel3
)
!=
0
)
return
1
;
if
(
createKernel
(
device_id
,
&
program
,
name_k4
,
&
kernel4
)
!=
0
)
return
1
;
if
(
createKernel
(
device_id
,
&
program
,
name_k5
,
&
kernel5
)
!=
0
)
return
1
;
// End of OpenCL Host Setup
// =======================================================================
...
...
@@ -1071,6 +1075,8 @@ if (strcmp(mypars->ls_method, "sw") == 0) {
clReleaseKernel
(
kernel4
);
clReleaseKernel
(
kernel5
);
clReleaseProgram
(
program
);
clReleaseCommandQueue
(
command_queue
);
clReleaseContext
(
context
);
free
(
device_id
);
...
...
wrapcl/inc/ImportSource.h
View file @
284b564b
...
...
@@ -45,12 +45,10 @@ int convertToString2(const char *filename, std::string& s);
/*
*/
int
ImportSource
(
const
char
*
filename
,
const
char
*
kernel_name
,
cl_device_id
*
device_id
,
cl_context
context
,
/*cl_program* program,*/
const
char
*
options
,
cl_kernel
*
kernel
);
int
ImportSourceToProgram
(
const
char
*
filename
,
cl_device_id
*
device_id
,
cl_context
context
,
cl_program
*
program
,
const
char
*
options
);
#endif
/* IMPORT_SOURCE_H */
wrapcl/inc/Kernels.h
View file @
284b564b
...
...
@@ -29,6 +29,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//#include <CL/opencl.h>
#include
"commonMacros.h"
int
createKernel
(
cl_device_id
*
device_id
,
cl_program
*
program
,
const
char
*
kernel_name
,
cl_kernel
*
kernel
);
/*
*/
...
...
wrapcl/src/ImportSource.cpp
View file @
284b564b
...
...
@@ -55,13 +55,11 @@ int convertToString2(const char *filename, std::string& s)
return
EXIT_FAILURE
;
}
int
ImportSource
(
const
char
*
filename
,
const
char
*
kernel_name
,
cl_device_id
*
device_id
,
cl_context
context
,
/*cl_program* program,*/
const
char
*
options
,
cl_kernel
*
kernel
)
int
ImportSourceToProgram
(
const
char
*
filename
,
cl_device_id
*
device_id
,
cl_context
context
,
cl_program
*
program
,
const
char
*
options
)
{
cl_int
err
;
...
...
@@ -78,17 +76,17 @@ int ImportSource(const char* filename,
// OCLADock
size_t
sourceSize
[]
=
{
strlen
(
source
)
};
cl_program
local_program
;
local_
program
=
clCreateProgramWithSource
(
context
,
1
,
&
source
,
sourceSize
,
&
err
);
*
program
=
clCreateProgramWithSource
(
context
,
1
,
&
source
,
sourceSize
,
&
err
);
if
((
!
local_
program
)
||
(
err
!=
CL_SUCCESS
)){
if
((
!
*
program
)
||
(
err
!=
CL_SUCCESS
)){
printf
(
"Error: clCreateProgramWithBinary() %d
\n
"
,
err
);
fflush
(
stdout
);
return
EXIT_FAILURE
;
}
#ifdef PROGRAM_INFO_DISPLAY
err
=
getProgramInfo
(
local_
program
);
err
=
getProgramInfo
(
*
program
);
if
(
err
!=
CL_SUCCESS
){
printf
(
"Error: getProgramInfo() %d
\n
"
,
err
);
fflush
(
stdout
);
...
...
@@ -96,28 +94,15 @@ int ImportSource(const char* filename,
}
#endif
/*Step 6: Build program. */
// Build the program executable
err
=
clBuildProgram
(
local_program
,
1
,
device_id
,
options
,
NULL
,
NULL
);
/*
if (err != CL_SUCCESS){
size_t len;
char buffer[2048];
printf("Error: clBuildProgram() %d\n", err);
clGetProgramBuildInfo(local_program, device_id[0], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
printf("%s\n", buffer);
fflush(stdout);
return EXIT_FAILURE;
}
*/
err
=
clBuildProgram
(
*
program
,
1
,
device_id
,
options
,
NULL
,
NULL
);
if
(
err
!=
CL_SUCCESS
)
{
int
err_build
;
size_t
sizeParam
;
char
*
program_build_log
;
err_build
=
clGetProgramBuildInfo
(
local_
program
,
device_id
[
0
],
CL_PROGRAM_BUILD_LOG
,
0
,
NULL
,
&
sizeParam
);
err_build
=
clGetProgramBuildInfo
(
*
program
,
device_id
[
0
],
CL_PROGRAM_BUILD_LOG
,
0
,
NULL
,
&
sizeParam
);
if
(
err_build
!=
CL_SUCCESS
){
printf
(
"Error: clGetProgramBuildInfo() %d
\n
"
,
err_build
);
fflush
(
stdout
);
...
...
@@ -125,7 +110,7 @@ int ImportSource(const char* filename,
}
program_build_log
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
sizeParam
);
err_build
=
clGetProgramBuildInfo
(
local_
program
,
device_id
[
0
],
CL_PROGRAM_BUILD_LOG
,
sizeParam
,
program_build_log
,
NULL
);
err_build
=
clGetProgramBuildInfo
(
*
program
,
device_id
[
0
],
CL_PROGRAM_BUILD_LOG
,
sizeParam
,
program_build_log
,
NULL
);
if
(
err_build
!=
CL_SUCCESS
){
printf
(
"Error: clGetProgramBuildInfo() %d
\n
"
,
err_build
);
fflush
(
stdout
);
...
...
@@ -143,17 +128,8 @@ int ImportSource(const char* filename,
return
EXIT_FAILURE
;
}
#ifdef PROGRAM_BUILD_INFO_DISPLAY
err
=
getprogramBuildInfo
(
local_
program
,
device_id
[
0
]);
err
=
getprogramBuildInfo
(
*
program
,
device_id
[
0
]);
if
(
err
!=
CL_SUCCESS
){
printf
(
"Error: getprogramBuildInfo() %d
\n
"
,
err
);
fflush
(
stdout
);
...
...
@@ -161,39 +137,5 @@ int ImportSource(const char* filename,
}
#endif
// Create the compute kernel in the program we wish to run
cl_kernel
local_kernel
;
local_kernel
=
clCreateKernel
(
local_program
,
kernel_name
,
&
err
);
if
((
!
local_kernel
)
||
(
err
!=
CL_SUCCESS
)){
printf
(
"Error: clCreateKernel() %s %d
\n
"
,
kernel_name
,
err
);
fflush
(
stdout
);
return
EXIT_FAILURE
;
}
#ifdef KERNEL_INFO_DISPLAY
err
=
getKernelInfo
(
local_kernel
);
if
(
err
!=
CL_SUCCESS
){
printf
(
"Error: getKernelInfo() %d
\n
"
,
kernel_name
,
err
);
fflush
(
stdout
);
return
EXIT_FAILURE
;
}
#endif
#ifdef KERNEL_WORK_GROUP_INFO_DISPLAY
err
=
getKernelWorkGroupInfo
(
local_kernel
,
device_id
[
0
]);
if
(
err
!=
CL_SUCCESS
){
printf
(
"Error: getKernelWorkGroupInfo() %d
\n
"
,
kernel_name
,
err
);
fflush
(
stdout
);
return
EXIT_FAILURE
;
}
#endif
// Release all program objects.
// Otherwise, memory leak in clCreateProgramWithSource()
clReleaseProgram
(
local_program
);
/* *program = local_program;*/
*
kernel
=
local_kernel
;
return
CL_SUCCESS
;
}
wrapcl/src/Kernels.cpp
View file @
284b564b
...
...
@@ -24,6 +24,44 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include
"Kernels.h"
int
createKernel
(
cl_device_id
*
device_id
,
cl_program
*
program
,
const
char
*
kernel_name
,
cl_kernel
*
kernel
)
{
cl_int
err
;
// Create the compute kernel in the program we wish to run
*
kernel
=
clCreateKernel
(
*
program
,
kernel_name
,
&
err
);
if
((
!
*
kernel
)
||
(
err
!=
CL_SUCCESS
)){
printf
(
"Error: clCreateKernel() %s %d
\n
"
,
kernel_name
,
err
);
fflush
(
stdout
);
return
EXIT_FAILURE
;
}
#ifdef KERNEL_INFO_DISPLAY
err
=
getKernelInfo
(
*
kernel
);
if
(
err
!=
CL_SUCCESS
){
printf
(
"Error: getKernelInfo() %d
\n
"
,
kernel_name
,
err
);
fflush
(
stdout
);
return
EXIT_FAILURE
;
}
#endif
#ifdef KERNEL_WORK_GROUP_INFO_DISPLAY
err
=
getKernelWorkGroupInfo
(
*
kernel
,
device_id
[
0
]);
if
(
err
!=
CL_SUCCESS
){
printf
(
"Error: getKernelWorkGroupInfo() %d
\n
"
,
kernel_name
,
err
);
fflush
(
stdout
);
return
EXIT_FAILURE
;
}
#endif
return
CL_SUCCESS
;
}
#ifdef KERNEL_INFO_DISPLAY
int
getKernelInfo
(
cl_kernel
kernel
){
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment