gpt4 book ai didi

c - 这个变量值在函数中如何变化?

转载 作者:太空宇宙 更新时间:2023-11-04 02:25:45 25 4
gpt4 key购买 nike

我有这个代码:

device_params_t *device_params = malloc(sizeof(device_params_t));

get_device_params(device_params, platform_id, workWithUser ? "check_pdfs_user" : "check_pdfs_owner", program_buffer, program_size);

int password_len = strlen(password_prefix) + password_digits + strlen(password_suffix);

unsigned int prefix_length = strlen(password_prefix), suffix_length = strlen(password_suffix);
unsigned long count;

// while (number < max_password) {
count = max_password - number;
count = count > batch_size ? batch_size : count;
printf("%lu\n", count);
run_on_gpu(device_params, params, number, password_prefix, prefix_length, password_suffix, suffix_length, password_len, count, &found);
printf("%lu\n", count);
if (found) {
// break;
}
number += count;
// }

这是 get_device_params 函数:

void get_device_params(device_params_t* params, cl_platform_id platform_id, const char *kernel_func, char *program_buffer, size_t program_size) {
clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 0, NULL, &params->device_count);
params->device_ids = (cl_device_id*) malloc(sizeof(cl_device_id) * params->device_count);
int err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, params->device_count, params->device_ids, NULL);
if (err != CL_SUCCESS)
{
printf("Error: Failed to create a device group! %d\n", err);
free(params->device_ids);
return;
}

int i;
size_t local, min_local = 0;

params->context = clCreateContext(NULL, params->device_count, params->device_ids, NULL, NULL, &err);
if (err != CL_SUCCESS)
{
printf("Error: Failed to create a compute context!\n");
goto out1;
}

cl_program program = build_program(params->context, params->device_ids, program_buffer, program_size);
if (!program)
{
printf("Error: Failed to create compute program!\n");
goto out1;
}

params->kernel = clCreateKernel(program, kernel_func, &err);
if (!params->kernel || err != CL_SUCCESS)
{
printf("Error: Failed to create compute kernel!\n");
goto out1;
}

params->commands = malloc(sizeof(cl_command_queue) * params->device_count);

for(i = 0; i < params->device_count; i++) {
params->commands[i] = clCreateCommandQueue(params->context, params->device_ids[i], 0, &err);
if (!params->commands[i])
{
printf("Error: Failed to create a command commands! %d\n", err);
goto out1;
}

err = clGetKernelWorkGroupInfo(params->kernel, params->device_ids[i], CL_KERNEL_WORK_GROUP_SIZE, sizeof(local), &local, NULL);
if (err != CL_SUCCESS)
{
printf("Error: Failed to retrieve kernel work group info! %d\n", err);
goto out1;
}

min_local = min_local > local ? local : min_local;
}

params->local = min_local;

return;

out1:
if (params->kernel) {
clReleaseKernel(params->kernel);
}
if (params->commands) {
for(i = 0; i < params->device_count; i++) {
clReleaseCommandQueue(params->commands[i]);
}
}
if (params->context) {
clReleaseKernel(params->context);
}
clReleaseProgram(program);

return;
}

run_on_gpu 定义为:

void run_on_gpu(device_params_t *device_params, PDFParams *params, unsigned long start, char *prefix, unsigned int prefix_length, char *suffix, unsigned int suffix_length, int password_length, const unsigned long cnt, bool *found)
{
printf("size %lu\n", cnt);
}

现在发生的事情是这样的:

9
size 549755813890
9

我希望它是:

9
size 9
9

不确定发生了什么!

最佳答案

在 SWAG 中,run_on_gpu() 的使用和定义存在参数不匹配。 549755813890 在您将其视为 64 位十六进制数之前并不是很有趣。此时它变为 0x00000080:00000002,在 32 位组之间插入冒号。这让我大吃一惊,run_on_gpu() 中的参数 cnt 以某种方式覆盖了另外两个 32 位值。

值得注意的是,这与 64 位系统上的 GCC 一致,但与任何平台上的 32 位 GCC 或 MSVC 不一致。据我所知,64 位 GCC 是唯一将 unsigned long 视为 64 位的“桌面”编译器,所有其他编译器均将其视为 32 位。

关于c - 这个变量值在函数中如何变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51525142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com