Author

Topic: c++ problem (Read 156 times)

member
Activity: 206
Merit: 16
February 28, 2023, 04:22:41 AM
#12
hash160 << <3, BLOCK_SIZE >> >(dev_pattern, dev_out, dev_nonce);

same error
full member
Activity: 161
Merit: 230
February 27, 2023, 05:15:03 PM
#11
<<>> is an extension to C++ to launch CUDA kernels, it is perfectly valid in CUDA code

https://medium.com/analytics-vidhya/cuda-compute-unified-device-architecture-part-2-f3841c25375e

CUDA I don't know  Sad
So the only error is that extra space and should have been
Code:
hash160 <<< 3, BLOCK_SIZE >>>(dev_pattern, dev_out, dev_nonce);
??

Or also Visual Studio doesn't handle this well or is missing something?
That Medium page also tells (yeah, that guy was installing on Linux) about CUDA Toolkit and so on.

The space doesn't matter, Visual Studio autocorrects it to << > > and it will still compile fine if everything's set up correctly.
legendary
Activity: 3668
Merit: 6382
Looking for campaign manager? Contact icopress!
February 27, 2023, 04:59:43 PM
#10
<<>> is an extension to C++ to launch CUDA kernels, it is perfectly valid in CUDA code

https://medium.com/analytics-vidhya/cuda-compute-unified-device-architecture-part-2-f3841c25375e

CUDA I don't know  Sad
So the only error is that extra space and should have been
Code:
hash160 <<< 3, BLOCK_SIZE >>>(dev_pattern, dev_out, dev_nonce);
??

Or also Visual Studio doesn't handle this well or is missing something?
That Medium page also tells (yeah, that guy was installing on Linux) about CUDA Toolkit and so on.
full member
Activity: 161
Merit: 230
February 27, 2023, 04:42:03 PM
#9
I solved everything but there is still one small problem

hash160 << < 3, BLOCK_SIZE >> >(dev_pattern, dev_out, dev_nonce);

<<< works in java, not in C++
<< < needs something in between (a bitwise shift maybe and then a comparison?)

But, since in the first post we have

Code:
__global__ void hash160(char *pattern, unsigned char *out, uint32_t *nonce)

you seem to be calling that void function, hence I would comment that erroneous line (at least for now) and put instead:

Code:
hash160(dev_pattern, dev_out, dev_nonce);

I have difficulties to understand what you aim for with a code you cannot even read.

<<>> is an extension to C++ to launch CUDA kernels, it is perfectly valid in CUDA code

https://medium.com/analytics-vidhya/cuda-compute-unified-device-architecture-part-2-f3841c25375e
legendary
Activity: 3668
Merit: 6382
Looking for campaign manager? Contact icopress!
February 27, 2023, 04:03:50 PM
#8
I solved everything but there is still one small problem

hash160 << < 3, BLOCK_SIZE >> >(dev_pattern, dev_out, dev_nonce);

<<< works in java, not in C++
<< < needs something in between (a bitwise shift maybe and then a comparison?)

But, since in the first post we have

__global__ void hash160(char *pattern, unsigned char *out, uint32_t *nonce)

you seem to be calling that void function, hence I would comment that erroneous line (at least for now) and put instead:

hash160(dev_pattern, dev_out, dev_nonce);




It seems that I was wrong, sorry, see below.
member
Activity: 206
Merit: 16
February 27, 2023, 01:17:02 PM
#7
yes but it doesn't change anything
full member
Activity: 161
Merit: 230
February 27, 2023, 01:01:50 PM
#6
When you created the project, did you create it as a CUDA project so it uses the CUDA compiler?
member
Activity: 206
Merit: 16
February 27, 2023, 11:21:28 AM
#5
I solved everything but there is still one small problem

hash160 << < 3, BLOCK_SIZE >> >(dev_pattern, dev_out, dev_nonce);

in red probleme

hero member
Activity: 862
Merit: 662
February 27, 2023, 10:49:04 AM
#4
Where that code come from, seems that you only copy and paste part of some code.

The variables that you are refering don't exist:

Code:
uint32_t index = blockIdx.x * blockDim.x + threadIdx.x;

blockIdx, blockDim and threadIdx  aren't declared anywhere.

Regards!
member
Activity: 206
Merit: 16
February 27, 2023, 10:04:06 AM
#3
I installed openssl but nothing works
full member
Activity: 161
Merit: 230
February 27, 2023, 10:00:22 AM
#2
Those are probably just warnings because Visual Studio doesn't always know about internal CUDA variables. The main issue is that it can't find your OpenSSL header file, that's what's blocking the compile.
member
Activity: 206
Merit: 16
February 27, 2023, 07:56:56 AM
#1
Code:
#include
#include
#include
#include
#include
#include

#define BLOCK_SIZE 1024

__global__ void hash160(char *pattern, unsigned char *out, uint32_t *nonce)
{
uint32_t index = blockIdx.x * blockDim.x + threadIdx.x;

unsigned char hash[SHA256_DIGEST_LENGTH];
char str[64];

for (int i = 0; i < 9; i++) {
str[i] = pattern[i];
}

for (uint32_t i = *nonce; i < UINT32_MAX; i += gridDim.x * blockDim.x) {
sprintf(&str[9], "%08x", i);
SHA256((const unsigned char*)str, strlen(str), hash);
RIPEMD160(hash, SHA256_DIGEST_LENGTH, &out[index * 20]);
if (out[index * 20] == 0x00 && out[index * 20 + 1] == 0x00) {
// Found a match!
*nonce = i;
break;
}
}
}

int main()
{
char pattern[10] = "1abcdefg"; // 9 characters pattern

  // Allocate memory on the host
unsigned char *out = new unsigned char[3 * 20];
uint32_t *nonce = new uint32_t;
*nonce = 0;

// Allocate memory on the device
char *dev_pattern;
unsigned char *dev_out;
uint32_t *dev_nonce;

cudaMalloc((void**)&dev_pattern, 10);
cudaMalloc((void**)&dev_out, 3 * 20);
cudaMalloc((void**)&dev_nonce, sizeof(uint32_t));

// Copy input data to the device
cudaMemcpy(dev_pattern, pattern, 10, cudaMemcpyHostToDevice);
cudaMemcpy(dev_out, out, 3 * 20, cudaMemcpyHostToDevice);
cudaMemcpy(dev_nonce, nonce, sizeof(uint32_t), cudaMemcpyHostToDevice);

// Launch the kernel
hash160 << < 3, BLOCK_SIZE >> >(dev_pattern, dev_out, dev_nonce);

// Copy output data from the device
cudaMemcpy(out, dev_out, 3 * 20, cudaMemcpyDeviceToHost);
cudaMemcpy(nonce, dev_nonce, sizeof(uint32_t), cudaMemcpyDeviceToHost);

// Print the results
for (int i = 0; i < 3; i++) {
std::cout << "Address " << i + 1 << ": " << std::setbase(16);
for (int j = 0; j < 20; j++) {
std::cout << std::setw(2) << std::setfill('0') << (int)out[i * 20 + j];
}
std::cout << std::endl;
}
std::cout << "Nonce: " << *nonce << std::endl;

// Free memory
delete[] out;
delete nonce;
cudaFree(dev_pattern);
cudaFree(dev_out);
cudaFree(dev_nonce);

return 0;
}

blockIdx.x * blockDim.x + threadIdx.x undefinited why Huh

Jump to: