-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrun_kernel.m
More file actions
executable file
·82 lines (71 loc) · 3.93 KB
/
run_kernel.m
File metadata and controls
executable file
·82 lines (71 loc) · 3.93 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
%This project is licensed under the terms of the Creative Commons CC BY-NC-ND 4.0 license.
clear all
close all
clc
%%
% Use cl_run_kernel to compile and launch kernels. It is possible to compile
% and run kernels in a two-stage process to increase performance or just use
% a single step approach, that does everything in one go.
global_range=[10,1,1]; %Set global OpenCl Range. Default indexing is 3D. To use a 1D index set y and z to 1
local_range=[0]; %Let OpenCL decide local range, otherwise specify range explicitly (like global range)
% Create input data for the kernel
for i=1:20
in1(1,i)=double(1);
in1(2,i)=double(1);
in1(3,i)=double(1);
in1(4,i)=double(1);
in2(1,i)=double(2);
in2(2,i)=double(2);
in2(3,i)=double(2);
in2(4,i)=double(2);
end
% This example shows how to only compile the kernel but not run it. The
% arguments are as follows:
% - OpenCl Device ID - see cl_get_devices
% - Kernel file URL
% - Kernel defines, can be used to efficently define constant values or set
% other compiler arguments
%
%This functions returns the compile time (in us) and an array with the names of the compiled kernel
%functions
%The OpenCL optimization flags -cl-mad-enable -cl-no-signed-zeros
%-cl-finite-math-only were tested on diffrent devices and sould not cause
%unexpected behaviour
[comp_time,kernels]=cl_run_kernel(1,'test_kernel.cl','-DDT=1.0 -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only');
% This example shows how to run a precompiled kernel. The
% arguments are as follows:
% - OpenCl Device ID - see cl_get_devices
% - Name of the function to run or cell array of kernel names to queue
% multiple kernels
% - Global OpenCL Range used to launch the kernel (see OpenCL NDRange)
% - Local OpenCL Range used to launch the kernel (see OpenCL NDRange). This
% value can be set to 0 to let OpenCL decide the best values
% - List of varaibles to be used by the kernel - they will be passed in the
% same order to the kernel itself. In case these variables get changed by
% the kernel, the value of the input variable will change automatically
% - read/write flag for the Kernel variables, this can either be scalar(all variables are read&write) or a vector with an entry for each variable: 0 - read&write / 1 - kernel read
% only / 2 - kernel write only.
%
%This function returns the runtime of the actual kernel and teh buffer copy time in us
[run_time,copy_time]=cl_run_kernel(1,'test1',global_range,local_range,in1,in2,0);
% This example shows how to compile and execute a kernel in a single pass.
% The arguments are as follows:
% - OpenCl Device ID - see cl_get_devices
% - Kernel file URL
% - Kernel defines, can be used to efficently define constant values or set
% other compiler arguments
% - Name of the function to run or cell array of kernel names to queue
% multiple kernels
% - Global OpenCL Range used to launch the kernel (see OpenCL NDRange)
% - Local OpenCL Range used to launch the kernel (see OpenCL NDRange). This
% value can be set to 0 to let OpenCL decide the best values
% - List of varaibles to be used by the kernel - they will be passed in the
% same order to the kernel itself. In case these variables get changed by
% the kernel, the value of the input variable will change automatically
% - read/write flag for the Kernel variables, this can either be scalar(all variables are read&write) or a vector with an entry for each variable: 0 - read&write / 1 - kernel read
% only / 2 - kernel write only.
%
%This function returns the runtime of the actual kernel in ms
[run_time]=cl_run_kernel(1,'test_kernel.cl','-DDT=5.0 -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only','test2',global_range,local_range,in1,in2,[0 1]);
%Same as above. but this functions pipes kernel printf to Matlab
[run_time]=cl_dbg_kernel(1,'test_kernel.cl','-DDT=5.0 -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only','test2',global_range,local_range,in1,in2,[0 1]);