Skip to content

Commit e70f260

Browse files
committed
Embed OpenCL code into executable to external files aren't necessary
Added 'embedcl' tool which takes a text file and encodes it into a C++ file and can be accessed with provided symbol.
1 parent 34add47 commit e70f260

File tree

17 files changed

+287
-27
lines changed

17 files changed

+287
-27
lines changed

BitCrack.sln

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "util", "util\util.vcxproj",
1111
EndProject
1212
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AddressUtil", "AddressUtil\AddressUtil.vcxproj", "{34042455-D274-432D-9134-C9EA41FD1B54}"
1313
EndProject
14-
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KeyFinder", "KeyFinder\KeyFinder.vcxproj", "{D77642A9-365C-420C-A726-469649D2927E}"
14+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cuKeyFinder", "KeyFinder\KeyFinder.vcxproj", "{D77642A9-365C-420C-A726-469649D2927E}"
1515
ProjectSection(ProjectDependencies) = postProject
1616
{53EE0C03-4419-4767-A91B-7FC7D4B3D2AA} = {53EE0C03-4419-4767-A91B-7FC7D4B3D2AA}
1717
{CCA3D02C-5E5A-4A24-B34B-5961DFA93946} = {CCA3D02C-5E5A-4A24-B34B-5961DFA93946}
@@ -65,6 +65,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clKeyFinder", "clKeyFinder\
6565
{BFF4B5FE-C2C5-4384-8941-CD6CB29E78C6} = {BFF4B5FE-C2C5-4384-8941-CD6CB29E78C6}
6666
EndProjectSection
6767
EndProject
68+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "embedcl", "embedcl\embedcl.vcxproj", "{8DA841AA-42FF-40AA-8F12-BC654DF39FEF}"
69+
EndProject
6870
Global
6971
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7072
Debug|x64 = Debug|x64
@@ -193,6 +195,14 @@ Global
193195
{36400E8D-3D04-430C-90A4-FC989E460B3C}.Release|x64.Build.0 = Release|x64
194196
{36400E8D-3D04-430C-90A4-FC989E460B3C}.Release|x86.ActiveCfg = Release|Win32
195197
{36400E8D-3D04-430C-90A4-FC989E460B3C}.Release|x86.Build.0 = Release|Win32
198+
{8DA841AA-42FF-40AA-8F12-BC654DF39FEF}.Debug|x64.ActiveCfg = Debug|x64
199+
{8DA841AA-42FF-40AA-8F12-BC654DF39FEF}.Debug|x64.Build.0 = Debug|x64
200+
{8DA841AA-42FF-40AA-8F12-BC654DF39FEF}.Debug|x86.ActiveCfg = Debug|Win32
201+
{8DA841AA-42FF-40AA-8F12-BC654DF39FEF}.Debug|x86.Build.0 = Debug|Win32
202+
{8DA841AA-42FF-40AA-8F12-BC654DF39FEF}.Release|x64.ActiveCfg = Release|x64
203+
{8DA841AA-42FF-40AA-8F12-BC654DF39FEF}.Release|x64.Build.0 = Release|x64
204+
{8DA841AA-42FF-40AA-8F12-BC654DF39FEF}.Release|x86.ActiveCfg = Release|Win32
205+
{8DA841AA-42FF-40AA-8F12-BC654DF39FEF}.Release|x86.Build.0 = Release|Win32
196206
EndGlobalSection
197207
GlobalSection(SolutionProperties) = preSolution
198208
HideSolutionNode = FALSE

CLKeySearchDevice/CLKeySearchDevice.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include "util.h"
44
#include "CLKeySearchDevice.h"
55

6+
// Defined in bitcrack_cl.cpp which gets build in the pre-build event
7+
extern char _bitcrack_cl[];
8+
69
typedef struct {
710
int thread;
811
int block;
@@ -48,8 +51,9 @@ CLKeySearchDevice::CLKeySearchDevice(uint64_t device, int threads, int pointsPer
4851
try {
4952
// Create the context
5053
_clContext = new cl::CLContext(_device);
51-
Logger::log(LogLevel::Info, "Compiling 'KeySearch.cl'...");
52-
_clProgram = new cl::CLProgram(*_clContext, util::getExeDirectory() + "KeySearch.cl");
54+
Logger::log(LogLevel::Info, "Compiling OpenCL kernels...");
55+
//_clProgram = new cl::CLProgram(*_clContext, util::getExeDirectory() + "KeySearch.cl");
56+
_clProgram = new cl::CLProgram(*_clContext, _bitcrack_cl);
5357

5458
// Load the kernels
5559
_initKeysKernel = new cl::CLKernel(*_clProgram, "multiplyStepKernel");

CLKeySearchDevice/CLKeySearchDevice.vcxproj

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@
8989
<EnableCOMDATFolding>true</EnableCOMDATFolding>
9090
<OptimizeReferences>true</OptimizeReferences>
9191
</Link>
92+
<PostBuildEvent>
93+
<Command>
94+
</Command>
95+
</PostBuildEvent>
96+
<PreBuildEvent>
97+
<Command>type ripemd160.cl secp256k1.cl sha256.cl keysearch.cl &gt; bitcrack.cl
98+
$(SolutionDir)\tools\embedcl.exe bitcrack.cl bitcrack_cl.cpp _bitcrack_cl</Command>
99+
<Message>Embed bitcrack.cl into bitcrack_cl.cpp</Message>
100+
</PreBuildEvent>
92101
</ItemDefinitionGroup>
93102
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
94103
<ClCompile>
@@ -99,6 +108,11 @@
99108
<AdditionalIncludeDirectories>$(SolutionDir)\KeyFinderLib;$(SolutionDir)\clUtil;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\include;$(SolutionDir)\secp256k1lib;$(SolutionDir)\Logger;$(SolutionDir)\util;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
100109
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
101110
</ClCompile>
111+
<PreBuildEvent>
112+
<Command>type ripemd160.cl secp256k1.cl sha256.cl keysearch.cl &gt; bitcrack.cl
113+
$(SolutionDir)\tools\embedcl.exe bitcrack.cl bitcrack_cl.cpp _bitcrack_cl</Command>
114+
<Message>Embed bitcrack.cl into bitcrack_cl.cpp</Message>
115+
</PreBuildEvent>
102116
</ItemDefinitionGroup>
103117
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104118
<ClCompile>
@@ -109,6 +123,15 @@
109123
<AdditionalIncludeDirectories>$(SolutionDir)\KeyFinderLib;$(SolutionDir)\clUtil;$(OPENCL_INCLUDE);$(SolutionDir)\secp256k1lib;$(SolutionDir)\Logger;$(SolutionDir)\util;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
110124
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
111125
</ClCompile>
126+
<PostBuildEvent>
127+
<Command>
128+
</Command>
129+
</PostBuildEvent>
130+
<PreBuildEvent>
131+
<Command>type ripemd160.cl secp256k1.cl sha256.cl keysearch.cl &gt; bitcrack.cl
132+
$(SolutionDir)\tools\embedcl.exe bitcrack.cl bitcrack_cl.cpp _bitcrack_cl</Command>
133+
<Message>Embed bitcrack.cl into bitcrack_cl.cpp</Message>
134+
</PreBuildEvent>
112135
</ItemDefinitionGroup>
113136
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
114137
<ClCompile>
@@ -125,11 +148,17 @@
125148
<EnableCOMDATFolding>true</EnableCOMDATFolding>
126149
<OptimizeReferences>true</OptimizeReferences>
127150
</Link>
151+
<PreBuildEvent>
152+
<Command>type ripemd160.cl secp256k1.cl sha256.cl keysearch.cl &gt; bitcrack.cl
153+
$(SolutionDir)\tools\embedcl.exe bitcrack.cl bitcrack_cl.cpp _bitcrack_cl</Command>
154+
<Message>Embed bitcrack.cl into bitcrack_cl.cpp</Message>
155+
</PreBuildEvent>
128156
</ItemDefinitionGroup>
129157
<ItemGroup>
130158
<ClInclude Include="CLKeySearchDevice.h" />
131159
</ItemGroup>
132160
<ItemGroup>
161+
<ClCompile Include="bitcrack_cl.cpp" />
133162
<ClCompile Include="CLKeySearchDevice.cpp" />
134163
</ItemGroup>
135164
<ItemGroup>

CLKeySearchDevice/keysearch.cl

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
#include "sha256.cl"
2-
#include "ripemd160.cl"
3-
#include "secp256k1.cl"
4-
51
#define COMPRESSED 0
62
#define UNCOMPRESSED 1
73
#define BOTH 2
84

9-
/*
10-
typedef struct {
11-
ulong mask;
12-
ulong size;
13-
unsigned int *ptr;
14-
}CLTargetList;
15-
*/
16-
175
unsigned int endian(unsigned int x)
186
{
197
return (x << 24) | ((x << 8) & 0x00ff0000) | ((x >> 8) & 0x0000ff00) | (x >> 24);
@@ -426,4 +414,4 @@ __kernel void keyFinderKernelWithDouble(
426414
__global unsigned int *numResults)
427415
{
428416
doIterationWithDouble(pointsPerThread, compression, chain, xPtr, yPtr, incXPtr, incYPtr, targetList, numTargets, mask, results, numResults);
429-
}
417+
}

CLKeySearchDevice/ripemd160.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,4 @@ void ripemd160sha256NoFinal(const unsigned int x[8], unsigned int digest[5])
491491
digest[3] = a1 + b2;
492492
digest[4] = b1 + c2;
493493
}
494-
#endif
494+
#endif

CLKeySearchDevice/secp256k1.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,4 +637,4 @@ void doBatchInverse(unsigned int inverse[8])
637637
invModP(inverse);
638638
}
639639

640-
#endif
640+
#endif

CLKeySearchDevice/sha256.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,4 @@ void sha256PublicKeyCompressed(const unsigned int x[8], unsigned int yParity, un
511511
digest[6] = g;
512512
digest[7] = h;
513513
}
514-
#endif
514+
#endif

CudaKeySearchDevice/CudaKeySearchDevice.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<CudaCompile>
8585
<TargetMachinePlatform>64</TargetMachinePlatform>
8686
<GenerateRelocatableDeviceCode>true</GenerateRelocatableDeviceCode>
87-
<CodeGeneration>compute_30,sm_30;compute_35,sm_35;compute_50,sm_50;compute_52,sm_52;compute_61,sm_61;compute_70,sm_70;%(CodeGeneration)</CodeGeneration>
87+
<CodeGeneration>%(CodeGeneration)</CodeGeneration>
8888
</CudaCompile>
8989
</ItemDefinitionGroup>
9090
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -107,7 +107,7 @@
107107
<CudaCompile>
108108
<TargetMachinePlatform>64</TargetMachinePlatform>
109109
<GenerateRelocatableDeviceCode>true</GenerateRelocatableDeviceCode>
110-
<CodeGeneration>compute_30,sm_30;compute_35,sm_35;compute_50,sm_50;compute_52,sm_52;compute_61,sm_61;compute_70,sm_70;%(CodeGeneration)</CodeGeneration>
110+
<CodeGeneration>%(CodeGeneration)</CodeGeneration>
111111
</CudaCompile>
112112
</ItemDefinitionGroup>
113113
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

KeyFinder/DeviceManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ std::vector<DeviceManager::DeviceInfo> DeviceManager::getDevices()
2525
device.type = DeviceType::CUDA;
2626
device.id = deviceId;
2727
device.physicalId = cudaDevices[i].id;
28+
device.memory = cudaDevices[i].mem;
2829

2930
devices.push_back(device);
3031

@@ -46,6 +47,7 @@ std::vector<DeviceManager::DeviceInfo> DeviceManager::getDevices()
4647
device.type = DeviceType::OpenCL;
4748
device.id = deviceId;
4849
device.physicalId = clDevices[i].id;
50+
device.memory = clDevices[i].mem;
4951

5052
devices.push_back(device);
5153
deviceId++;

KeyFinder/DeviceManager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ typedef struct {
3232
int id;
3333
uint64_t physicalId;
3434
std::string name;
35+
36+
uint64_t memory;
37+
38+
// CUDA device info
39+
int cudaMajor;
40+
int cudaMinor;
3541
}DeviceInfo;
3642

3743
std::vector<DeviceInfo> getDevices();

0 commit comments

Comments
 (0)