Skip to content

Commit efee8aa

Browse files
committed
* Issues with old graphic cards is solved:
* CL sources should be saved as plain text (ANSI, not UTF). Some old OpenCL compilers return error in case of UTF files. * Some graphic cards (Intel(R) HD Graphics 4400) cannot use doubles (no "cl_khr_fp64" extension). Therefore the CL sources were divided to float and double versions. The buttons "Run VBA performance test" and "Asynchronous execution" runs the "float" versions of CL sources because they can be executed at all kind of devices (hopefully). * Old version of Inno setup was used to compile the installation. Latest Inno setup version created the installation that was falsely detected as virus.
1 parent 42c075c commit efee8aa

12 files changed

+221
-152
lines changed

C#/Installation script.iss

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ AppName=ClooWrapperVBA
33
AppVerName=ClooWrapperVBA
44
DefaultDirName={pf}\ClooWrapperVBA
55
DefaultGroupName=ClooWrapperVBA
6-
Compression=lzma
6+
Compression=zip
77
SolidCompression=yes
88
SourceDir=.\
99
PrivilegesRequired=poweruser
@@ -22,9 +22,11 @@ Name: "{app}\demo\cl"; Permissions: everyone-full
2222
Source: bin\ClooWrapperVBA.dll; DestDir: {app}; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
2323
Source: bin\ClooWrapperVBA_x64.dll; DestDir: {app}; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
2424
Source: bin\Cloo.dll; DestDir: {app}; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
25-
Source: ..\Excel\OpenCl v0.05.xlsm; DestDir: {app}\demo; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
26-
Source: ..\Excel\cl\Performance.cl; DestDir: {app}\demo\cl; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
27-
Source: ..\Excel\cl\MatrixMultiplication.cl; DestDir: {app}\demo\cl; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
25+
Source: ..\Excel\OpenCl example.xlsm; DestDir: {app}\demo; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
26+
Source: ..\Excel\cl\FloatPerformance.cl; DestDir: {app}\demo\cl; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
27+
Source: ..\Excel\cl\DoublePerformance.cl; DestDir: {app}\demo\cl; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
28+
Source: ..\Excel\cl\FloatMatrixMultiplication.cl; DestDir: {app}\demo\cl; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
29+
Source: ..\Excel\cl\DoubleMatrixMultiplication.cl; DestDir: {app}\demo\cl; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
2830
Source: ..\Excel\Configuration.vbs; DestDir: {app}\demo; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
2931
Source: bin\register.bat; DestDir: {app}; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;
3032
Source: bin\unregister.bat; DestDir: {app}; Flags: ignoreversion recursesubdirs overwritereadonly; Permissions: everyone-full;

Excel/Asynchronous.bas

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Const THREAD_PRIORITY = 0
1010
Dim progDevices As Collection
1111
Dim currentTaskId&()
1212

13-
Dim vecResp#()
13+
Dim vecResp!()
1414
Dim wsAsynchronous As Worksheet
1515
Dim globalWorkSize&(1), localWorkSize&(), globalWorkOffset&()
1616
Dim logLine%
@@ -26,7 +26,7 @@ Sub MainLoop()
2626
While Not allTasks_Completed
2727
For i = 1 To progDevices.Count
2828
If progDevices.Item(i).ProgramDevice.ExecutionCompleted Then
29-
result = progDevices.Item(i).ProgramDevice.GetMemoryArgument_Double(0, vecResp) ' Extract the results and do something with received data here.
29+
result = progDevices.Item(i).ProgramDevice.GetMemoryArgument_Single(0, vecResp) ' Extract the results and do something with received data here.
3030

3131
wsAsynchronous.Cells(logLine, 1) = "Task " & currentTaskId(i) & ", " & progDevices.Item(i).ProgramDevice.deviceType & _
3232
progDevices.Item(i).DeviceId & ": completed"
@@ -37,7 +37,7 @@ Sub MainLoop()
3737
' Start new task
3838
If startedTasks < MAX_TASKS Then
3939
ReDim vecResp(UBound(vecResp)) ' Erase output vector.
40-
result = progDevices.Item(i).ProgramDevice.SetMemoryArgument_Double(0, vecResp)
40+
result = progDevices.Item(i).ProgramDevice.SetMemoryArgument_Single(0, vecResp)
4141

4242
' If you want to use callbacks, than use function below
4343
' "CPU_Task_Completed" is a function that will obtain the callback.
@@ -83,14 +83,14 @@ Sub MainLoop()
8383
End Sub
8484

8585
Sub RunAsynchronous()
86-
Dim vecM1#(), vecM2#()
86+
Dim vecM1!(), vecM2!()
8787
Dim vecQ&(1)
8888
Dim i&, j&, p&, q&, r&, nRows&
8989
Dim buildLogs$, sources$
9090

9191
Set wsAsynchronous = ThisWorkbook.Worksheets("Asynchronous")
9292

93-
Open Application.ActiveWorkbook.Path & "\cl\MatrixMultiplication.cl" For Binary As #1
93+
Open Application.ActiveWorkbook.Path & "\cl\FloatMatrixMultiplication.cl" For Binary As #1
9494
sources = Space$(LOF(1))
9595
Get #1, , sources
9696
Close #1
@@ -133,10 +133,10 @@ Sub RunAsynchronous()
133133

134134
ReDim currentTaskId(progDevices.Count)
135135
For i = 1 To progDevices.Count
136-
result = progDevices.Item(i).ProgramDevice.CreateKernel("DoubleMatrixMult")
137-
result = progDevices.Item(i).ProgramDevice.SetMemoryArgument_Double(0, vecResp)
138-
result = progDevices.Item(i).ProgramDevice.SetMemoryArgument_Double(1, vecM1)
139-
result = progDevices.Item(i).ProgramDevice.SetMemoryArgument_Double(2, vecM2)
136+
result = progDevices.Item(i).ProgramDevice.CreateKernel("FloatMatrixMult")
137+
result = progDevices.Item(i).ProgramDevice.SetMemoryArgument_Single(0, vecResp)
138+
result = progDevices.Item(i).ProgramDevice.SetMemoryArgument_Single(1, vecM1)
139+
result = progDevices.Item(i).ProgramDevice.SetMemoryArgument_Single(2, vecM2)
140140
result = progDevices.Item(i).ProgramDevice.SetMemoryArgument_Long(3, vecQ)
141141
Next i
142142

Excel/HelloWorld.bas

+17-17
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Sub HelloWorld()
66
Dim nRows%, currentRow&, nPlatforms&, nDevices&, i&, j&, result As Boolean
77
Dim deviceType$, platformName$, platformVendor$, platformVersion$, deviceVendor$, deviceVersion$, driverVersion$, openCLCVersionString$
88
Dim maxComputeUnits&, globalMemorySize#, maxClockFrequency#, maxMemoryAllocationSize#, deviceName$, sources$, cpuCounter&, gpuCounter&
9-
Dim buildLogs$, platformId&, deviceId&, errorString$
9+
Dim buildLogs$, platformId&, DeviceId&, errorString$
1010
Dim deviceAvailable As Boolean, compilerAvailable As Boolean
11-
Dim m1#(1, 1), m2#(1, 1), vecM1#(), vecM2#(), vecQ&(0), vecResp#(3), globalWorkOffset&(), globalWorkSize&(1), localWorkSize&()
12-
Dim p&, q&, r&, resp#()
11+
Dim m1!(1, 1), m2!(1, 1), vecM1!(), vecM2!(), vecQ&(0), vecResp!(3), globalWorkOffset&(), globalWorkSize&(1), localWorkSize&()
12+
Dim p&, q&, r&, resp!()
1313

1414
Dim clooConfiguration As New ClooWrapperVBA.Configuration
1515
Dim progDevice As ClooWrapperVBA.ProgramDevice
@@ -76,7 +76,7 @@ Sub HelloWorld()
7676

7777
' Multiplication of two matrices.
7878
' Read the OpenCL sources.
79-
Open Application.ActiveWorkbook.Path & "\cl\MatrixMultiplication.cl" For Binary As #1
79+
Open Application.ActiveWorkbook.Path & "\cl\FloatMatrixMultiplication.cl" For Binary As #1
8080
sources = Space$(LOF(1))
8181
Get #1, , sources
8282
Close #1
@@ -87,13 +87,13 @@ Sub HelloWorld()
8787
result = clooConfiguration.SetPlatform(platformId)
8888
cpuCounter = 0
8989
gpuCounter = 0
90-
For deviceId = 0 To clooConfiguration.Platform.Devices - 1
91-
result = clooConfiguration.Platform.SetDevice(deviceId)
90+
For DeviceId = 0 To clooConfiguration.Platform.Devices - 1
91+
result = clooConfiguration.Platform.SetDevice(DeviceId)
9292

9393
If clooConfiguration.Platform.device.compilerAvailable Then
9494
If clooConfiguration.Platform.device.deviceType = "CPU" Then
9595
Set progDevice = New ClooWrapperVBA.ProgramDevice
96-
result = progDevice.Build(sources, "", platformId, deviceId, cpuCounter, buildLogs)
96+
result = progDevice.Build(sources, "", platformId, DeviceId, cpuCounter, buildLogs)
9797
If result Then
9898
Exit Do
9999
Else
@@ -102,7 +102,7 @@ Sub HelloWorld()
102102
End If
103103
If clooConfiguration.Platform.device.deviceType = "GPU" Then
104104
Set progDevice = New ClooWrapperVBA.ProgramDevice
105-
result = progDevice.Build(sources, "", platformId, deviceId, gpuCounter, buildLogs)
105+
result = progDevice.Build(sources, "", platformId, DeviceId, gpuCounter, buildLogs)
106106
gpuCounter = gpuCounter + 1
107107
If result Then
108108
Exit Do
@@ -111,12 +111,12 @@ Sub HelloWorld()
111111
End If
112112
End If
113113
End If
114-
Next deviceId
114+
Next DeviceId
115115
platformId = platformId + 1
116116
Loop
117117

118118
errorString = progDevice.errorString
119-
result = progDevice.CreateKernel("DoubleMatrixMult")
119+
result = progDevice.CreateKernel("FloatMatrixMult")
120120

121121
' Initialization of arrays:
122122
p = 2: q = 2: r = 2
@@ -125,28 +125,28 @@ Sub HelloWorld()
125125
m1(i, j) = wsHelloWorld.Cells(i + 1, j + 7)
126126
Next j
127127
Next i
128-
vecM1 = MatrixToVector(m1, p, q)
128+
vecM1 = MatrixToVectorSingle(m1, p, q)
129129
For i = 0 To q - 1
130130
For j = 0 To r - 1
131131
m2(i, j) = wsHelloWorld.Cells(i + 3, j + 7)
132132
Next j
133133
Next i
134-
vecM2 = MatrixToVector(m2, q, r)
134+
vecM2 = MatrixToVectorSingle(m2, q, r)
135135
vecQ(0) = q
136136

137-
result = progDevice.SetMemoryArgument_Double(0, vecResp)
138-
result = progDevice.SetMemoryArgument_Double(1, vecM1)
139-
result = progDevice.SetMemoryArgument_Double(2, vecM2)
137+
result = progDevice.SetMemoryArgument_Single(0, vecResp)
138+
result = progDevice.SetMemoryArgument_Single(1, vecM1)
139+
result = progDevice.SetMemoryArgument_Single(2, vecM2)
140140
result = progDevice.SetMemoryArgument_Long(3, vecQ)
141141

142142
globalWorkSize(0) = p
143143
globalWorkSize(1) = r
144144

145145
result = progDevice.ExecuteSync(globalWorkOffset, globalWorkSize, localWorkSize)
146146

147-
result = progDevice.GetMemoryArgument_Double(0, vecResp)
147+
result = progDevice.GetMemoryArgument_Single(0, vecResp)
148148

149-
resp = VectorToMatrix(vecResp, p, r)
149+
resp = VectorToMatrixSingle(vecResp, p, r)
150150

151151
For i = 0 To p - 1
152152
For j = 0 To r - 1

Excel/Helpers.bas

+36-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ Function CreateDeviceCollection(sources$)
3737

3838
If clooConfiguration.Platform.device.deviceType = "CPU" Then
3939
result = progDevice.ProgramDevice.Build(sources, "", i - 1, j - 1, cpuCounter, buildLogs)
40-
progDevice.deviceId = cpuCounter
40+
progDevice.DeviceId = cpuCounter
4141
progDevice.deviceType = "CPU"
4242
If result = True Then cpuCounter = cpuCounter + 1
4343
ElseIf clooConfiguration.Platform.device.deviceType = "GPU" Then
4444
result = progDevice.ProgramDevice.Build(sources, "", i - 1, j - 1, gpuCounter, buildLogs)
45-
progDevice.deviceId = gpuCounter
45+
progDevice.DeviceId = gpuCounter
4646
progDevice.deviceType = "GPU"
4747
If result = True Then gpuCounter = gpuCounter + 1
4848
Else
@@ -62,7 +62,37 @@ Function CreateDeviceCollection(sources$)
6262
End If
6363
End Function
6464

65-
Function MatrixToVector(m() As Double, maxi As Long, maxj As Long) As Double()
65+
Function MatrixToVectorSingle(m() As Single, maxi As Long, maxj As Long) As Single()
66+
Dim v() As Single
67+
Dim i&, j&
68+
69+
ReDim v(maxi * maxj - 1)
70+
71+
For i = 0 To maxi - 1
72+
For j = 0 To maxj - 1
73+
v(i + maxi * j) = m(i, j)
74+
Next j
75+
Next i
76+
77+
MatrixToVectorSingle = v
78+
End Function
79+
80+
Function VectorToMatrixSingle(v() As Single, maxi As Long, maxj As Long) As Single()
81+
Dim i&, j&
82+
Dim m() As Single
83+
84+
ReDim m(maxi - 1, maxj - 1)
85+
86+
For i = 0 To maxi - 1
87+
For j = 0 To maxj - 1
88+
m(i, j) = v(i + maxi * j)
89+
Next j
90+
Next i
91+
92+
VectorToMatrixSingle = m
93+
End Function
94+
95+
Function MatrixToVectorDouble(m() As Double, maxi As Long, maxj As Long) As Double()
6696
Dim v() As Double
6797
Dim i&, j&
6898

@@ -74,10 +104,10 @@ Function MatrixToVector(m() As Double, maxi As Long, maxj As Long) As Double()
74104
Next j
75105
Next i
76106

77-
MatrixToVector = v
107+
MatrixToVectorDouble = v
78108
End Function
79109

80-
Function VectorToMatrix(v() As Double, maxi As Long, maxj As Long) As Double()
110+
Function VectorToMatrixDouble(v() As Double, maxi As Long, maxj As Long) As Double()
81111
Dim i&, j&
82112
Dim m() As Double
83113

@@ -89,5 +119,5 @@ Function VectorToMatrix(v() As Double, maxi As Long, maxj As Long) As Double()
89119
Next j
90120
Next i
91121

92-
VectorToMatrix = m
122+
VectorToMatrixDouble = m
93123
End Function

Excel/OpenCl example.xlsm

5.68 KB
Binary file not shown.

0 commit comments

Comments
 (0)