commit 94c4edf4a5b936503b6e7afb84c59e9b33376761
parent ba7f0ed534e534f30f8f7e8b4e13d7aadbf7d753
Author: Cedric <cedric.zwahlen@students.bfh.ch>
Date: Sun, 5 Nov 2023 01:38:39 +0100
The gpu calculates the correct signature (more or less), but it is quite slow. So far, the comparison of the signatures (to check if they are correct), is still done on the CPU, because that is easier to debug.
Diffstat:
7 files changed, 177 insertions(+), 47 deletions(-)
diff --git a/.DS_Store b/.DS_Store
Binary files differ.
diff --git a/source/rsa-test.c b/source/rsa-test.c
@@ -7,6 +7,7 @@
#include "rsa-test.h"
#include "big-int-test.h"
+
#include <OpenCL/opencl.h>
#include "ctype.h"
@@ -151,9 +152,7 @@ int rsa_tests(void) {
int err; // error code returned from api calls
- float data[DATA_SIZE]; // original data set given to device
- float results[DATA_SIZE]; // results returned from device
- unsigned int correct; // number of correct results returned
+ // number of correct results returned
size_t global; // global domain size for our calculation
size_t local; // local domain size for our calculation
@@ -167,9 +166,6 @@ int rsa_tests(void) {
//cl_mem input; // device memory used for the input array
//cl_mem output; // device memory used for the output array
-
- //int i = 0;
- unsigned int count = DATA_SIZE;
// Connect to a compute device
@@ -187,7 +183,7 @@ int rsa_tests(void) {
char driver_version[retSize_1];
clGetDeviceInfo(device_id, CL_DRIVER_VERSION, retSize_1, &driver_version, &retSize_1);
- printf("driver version: %s\n", driver_version);
+ //printf("driver version: %s\n", driver_version);
size_t retSize_2 = sizeof(cl_uint);
@@ -195,7 +191,7 @@ int rsa_tests(void) {
clGetDeviceInfo(device_id, CL_DEVICE_ADDRESS_BITS, 0, NULL, &retSize_2);
clGetDeviceInfo(device_id, CL_DEVICE_ADDRESS_BITS, retSize_2, &address_bits, &retSize_2);
- printf("device address bits: %i\n", address_bits);
+ //printf("device address bits: %i\n", address_bits);
// Create a compute context
@@ -301,11 +297,11 @@ int rsa_tests(void) {
unsigned long max_len = max(sz_s,sz_n);
- n_mem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(char) * n_len, NULL, NULL);
- e_mem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(char) * e_len, NULL, NULL);
- s_mem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(char) * s_len, NULL, NULL);
+ n_mem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(DIGIT_T) * n_len, NULL, NULL);
+ e_mem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(DIGIT_T) * e_len, NULL, NULL);
+ s_mem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(DIGIT_T) * s_len, NULL, NULL);
- res_mem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(char) * res_len, NULL, NULL);
+ res_mem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(DIGIT_T) * res_len, NULL, NULL);
valid = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int8_t), NULL, NULL);
@@ -322,10 +318,10 @@ int rsa_tests(void) {
// Write our data set into the input array in device memory
//
- err = clEnqueueWriteBuffer(commands, s_mem, CL_TRUE, 0, s_len, s_buf, 0, NULL, NULL);
- err |= clEnqueueWriteBuffer(commands, e_mem, CL_TRUE, 0, e_len, e_buf, 0, NULL, NULL);
- err |= clEnqueueWriteBuffer(commands, n_mem, CL_TRUE, 0, n_len, n_buf, 0, NULL, NULL);
- err |= clEnqueueWriteBuffer(commands, res_mem, CL_TRUE, 0, res_len, res_buf, 0, NULL, NULL);
+ err = clEnqueueWriteBuffer(commands, s_mem, CL_TRUE, 0, s_len * sizeof(DIGIT_T), s_buf, 0, NULL, NULL);
+ err |= clEnqueueWriteBuffer(commands, e_mem, CL_TRUE, 0, e_len * sizeof(DIGIT_T), e_buf, 0, NULL, NULL);
+ err |= clEnqueueWriteBuffer(commands, n_mem, CL_TRUE, 0, n_len * sizeof(DIGIT_T), n_buf, 0, NULL, NULL);
+ err |= clEnqueueWriteBuffer(commands, res_mem, CL_TRUE, 0, res_len * sizeof(DIGIT_T), res_buf, 0, NULL, NULL);
if (err != CL_SUCCESS)
{
printf("Error: Failed to write to source array!\n");
@@ -361,7 +357,12 @@ int rsa_tests(void) {
printf("Error: Failed to retrieve kernel work group info! %d\n", err);
exit(1);
}
-
+
+
+ struct timespec t3, t4;
+
+ clock_gettime(CLOCK_REALTIME, &t3);
+
// Execute the kernel over the entire range of our 1d input data set
// using the maximum number of work group items for this device
//
@@ -376,6 +377,9 @@ int rsa_tests(void) {
// Wait for the command commands to get serviced before reading back results
//
clFinish(commands);
+
+
+
// Read back the results from the device to verify the output
//
@@ -386,6 +390,13 @@ int rsa_tests(void) {
exit(1);
}
+ clock_gettime(CLOCK_REALTIME, &t4);
+
+ float seconds_2 = (t3.tv_nsec - t4.tv_nsec) / 1000;
+
+ printf("\nGPU verification: %f micro seconds\n", seconds_2);
+
+
size_t sz_res = mpSizeof(res_buf, MAX_ALLOC_SIZE*2);
int sz_mm = strlen(val) + 2;
@@ -397,8 +408,6 @@ int rsa_tests(void) {
printf("%s\n",comp);
// Print a brief summary detailing the results
- //
- // printf("Computed '%d/%d' correct values!\n", correct, count);
// Shutdown and cleanup
//
diff --git a/xcode/.DS_Store b/xcode/.DS_Store
Binary files differ.
diff --git a/xcode/lib-gpu-verify.xcodeproj/project.pbxproj b/xcode/lib-gpu-verify.xcodeproj/project.pbxproj
@@ -9,8 +9,8 @@
/* Begin PBXBuildFile section */
6A8A795D2A89357400116D7D /* rsa-kernel.cl in Sources */ = {isa = PBXBuildFile; fileRef = 6A8A795C2A89357400116D7D /* rsa-kernel.cl */; };
6A8A795F2A89672700116D7D /* verify.cl in Sources */ = {isa = PBXBuildFile; fileRef = 6A8A795E2A89672700116D7D /* verify.cl */; };
+ 6AD85E072AF71AD900662919 /* big-int-test.c in Sources */ = {isa = PBXBuildFile; fileRef = 6AF7487D2ADADF4500D58E08 /* big-int-test.c */; };
6AF7487A2ADADEBD00D58E08 /* lib-gpu-verify.c in Sources */ = {isa = PBXBuildFile; fileRef = 6AF748792ADADEBD00D58E08 /* lib-gpu-verify.c */; };
- 6AF748822ADADF4500D58E08 /* big-int-test.c in Sources */ = {isa = PBXBuildFile; fileRef = 6AF7487D2ADADF4500D58E08 /* big-int-test.c */; };
6AF748832ADADF4500D58E08 /* rsa-test.c in Sources */ = {isa = PBXBuildFile; fileRef = 6AF7487F2ADADF4500D58E08 /* rsa-test.c */; };
6AF748862ADADFAD00D58E08 /* opencl-test.c in Sources */ = {isa = PBXBuildFile; fileRef = 6AF748852ADADFAD00D58E08 /* opencl-test.c */; };
C3770EFD0E6F1138009A5A77 /* OpenCL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3770EFC0E6F1138009A5A77 /* OpenCL.framework */; };
@@ -157,12 +157,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 6AD85E072AF71AD900662919 /* big-int-test.c in Sources */,
6AF7487A2ADADEBD00D58E08 /* lib-gpu-verify.c in Sources */,
6A8A795D2A89357400116D7D /* rsa-kernel.cl in Sources */,
6A8A795F2A89672700116D7D /* verify.cl in Sources */,
6AF748832ADADF4500D58E08 /* rsa-test.c in Sources */,
6AF748862ADADFAD00D58E08 /* opencl-test.c in Sources */,
- 6AF748822ADADF4500D58E08 /* big-int-test.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/xcode/lib-gpu-verify.xcodeproj/project.xcworkspace/xcuserdata/cedriczwahlen.xcuserdatad/UserInterfaceState.xcuserstate b/xcode/lib-gpu-verify.xcodeproj/project.xcworkspace/xcuserdata/cedriczwahlen.xcuserdatad/UserInterfaceState.xcuserstate
Binary files differ.
diff --git a/xcode/lib-gpu-verify.xcodeproj/xcuserdata/cedriczwahlen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/xcode/lib-gpu-verify.xcodeproj/xcuserdata/cedriczwahlen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -690,8 +690,8 @@
filePath = "../source/rsa-test.c"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "397"
- endingLineNumber = "397"
+ startingLineNumber = "408"
+ endingLineNumber = "408"
landmarkName = "rsa_tests()"
landmarkType = "9">
<Locations>
@@ -783,8 +783,8 @@
filePath = "../source/rsa-test.c"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "316"
- endingLineNumber = "316"
+ startingLineNumber = "312"
+ endingLineNumber = "312"
landmarkName = "rsa_tests()"
landmarkType = "9">
<Locations>
@@ -824,31 +824,15 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
- uuid = "0B50C23D-36DE-4C9C-B911-72E48EA8C7FD"
- shouldBeEnabled = "No"
- ignoreCount = "0"
- continueAfterRunningActions = "No"
- filePath = "../source/rsa-test.c"
- startingColumnNumber = "9223372036854775807"
- endingColumnNumber = "9223372036854775807"
- startingLineNumber = "382"
- endingLineNumber = "382"
- landmarkName = "rsa_tests()"
- landmarkType = "9">
- </BreakpointContent>
- </BreakpointProxy>
- <BreakpointProxy
- BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
- <BreakpointContent
uuid = "CCA5ECFD-4BDD-4A9B-8C34-A3E9A049CB5C"
- shouldBeEnabled = "Yes"
+ shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../source/rsa-test.c"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "329"
- endingLineNumber = "329"
+ startingLineNumber = "325"
+ endingLineNumber = "325"
landmarkName = "rsa_tests()"
landmarkType = "9">
<Locations>
@@ -882,6 +866,111 @@
endingLineNumber = "329"
offsetFromSymbolStart = "3202">
</Location>
+ <Location
+ uuid = "CCA5ECFD-4BDD-4A9B-8C34-A3E9A049CB5C - b0b9078e770c9ae8"
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ symbolName = "rsa_tests"
+ moduleName = "lib-gpu-verify"
+ usesParentBreakpointCondition = "Yes"
+ urlString = "file:///Users/cedriczwahlen/libgpuverify/source/rsa-test.c"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "330"
+ endingLineNumber = "330"
+ offsetFromSymbolStart = "3202">
+ </Location>
+ <Location
+ uuid = "CCA5ECFD-4BDD-4A9B-8C34-A3E9A049CB5C - b0b9078e770c9985"
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ symbolName = "rsa_tests"
+ moduleName = "lib-gpu-verify"
+ usesParentBreakpointCondition = "Yes"
+ urlString = "file:///Users/cedriczwahlen/libgpuverify/source/rsa-test.c"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "325"
+ endingLineNumber = "325"
+ offsetFromSymbolStart = "3192">
+ </Location>
+ <Location
+ uuid = "CCA5ECFD-4BDD-4A9B-8C34-A3E9A049CB5C - b0b9078e770c9985"
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ symbolName = "rsa_tests"
+ moduleName = "lib-gpu-verify"
+ usesParentBreakpointCondition = "Yes"
+ urlString = "file:///Users/cedriczwahlen/libgpuverify/source/rsa-test.c"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "325"
+ endingLineNumber = "325"
+ offsetFromSymbolStart = "3218">
+ </Location>
+ <Location
+ uuid = "CCA5ECFD-4BDD-4A9B-8C34-A3E9A049CB5C - b0b9078e770c9985"
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ symbolName = "rsa_tests"
+ moduleName = "lib-gpu-verify"
+ usesParentBreakpointCondition = "Yes"
+ urlString = "file:///Users/cedriczwahlen/libgpuverify/source/rsa-test.c"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "325"
+ endingLineNumber = "325"
+ offsetFromSymbolStart = "3240">
+ </Location>
+ <Location
+ uuid = "CCA5ECFD-4BDD-4A9B-8C34-A3E9A049CB5C - b0b9078e770c9985"
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ symbolName = "rsa_tests"
+ moduleName = "lib-gpu-verify"
+ usesParentBreakpointCondition = "Yes"
+ urlString = "file:///Users/cedriczwahlen/libgpuverify/source/rsa-test.c"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "325"
+ endingLineNumber = "325"
+ offsetFromSymbolStart = "3264">
+ </Location>
+ <Location
+ uuid = "CCA5ECFD-4BDD-4A9B-8C34-A3E9A049CB5C - b0b9078e770c9985"
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ symbolName = "rsa_tests"
+ moduleName = "lib-gpu-verify"
+ usesParentBreakpointCondition = "Yes"
+ urlString = "file:///Users/cedriczwahlen/libgpuverify/source/rsa-test.c"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "325"
+ endingLineNumber = "325"
+ offsetFromSymbolStart = "3204">
+ </Location>
+ <Location
+ uuid = "CCA5ECFD-4BDD-4A9B-8C34-A3E9A049CB5C - b0b9078e770c9985"
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ symbolName = "rsa_tests"
+ moduleName = "lib-gpu-verify"
+ usesParentBreakpointCondition = "Yes"
+ urlString = "file:///Users/cedriczwahlen/libgpuverify/source/rsa-test.c"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "325"
+ endingLineNumber = "325"
+ offsetFromSymbolStart = "3208">
+ </Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
@@ -895,11 +984,43 @@
filePath = "../source/rsa-test.c"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "506"
- endingLineNumber = "506"
+ startingLineNumber = "515"
+ endingLineNumber = "515"
landmarkName = "verify(sign, ee, nn, mm)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
+ <BreakpointProxy
+ BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+ <BreakpointContent
+ uuid = "6E42D663-F5A4-4A31-A6DB-269D03688D3D"
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ filePath = "../source/kernel-c-impl.c"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "1136"
+ endingLineNumber = "1136"
+ landmarkName = "mpModExpO(yout, x, e, m, ndigits)"
+ landmarkType = "9">
+ </BreakpointContent>
+ </BreakpointProxy>
+ <BreakpointProxy
+ BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+ <BreakpointContent
+ uuid = "C05022BA-47E4-4B88-80FB-B18FDB3D88FA"
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ filePath = "../source/kernel-c-impl.c"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "1205"
+ endingLineNumber = "1205"
+ landmarkName = "mpModExpO(yout, x, e, m, ndigits)"
+ landmarkType = "9">
+ </BreakpointContent>
+ </BreakpointProxy>
</Breakpoints>
</Bucket>
diff --git a/xcode/verify.cl b/xcode/verify.cl
@@ -87,7 +87,7 @@ int mpIsZero( const DIGIT_T *a, size_t ndigits);
void mpFail(char *msg);
-int mpModExpO( DIGIT_T *yout, DIGIT_T *x, DIGIT_T *e, DIGIT_T *m, size_t ndigits);
+//int mpModExpO( DIGIT_T *yout, DIGIT_T *x, DIGIT_T *e, DIGIT_T *m, size_t ndigits);
void assert(bool precondition);