主頁 > 區塊鏈 > clEnqueueWriteBuffer上的OpenCLCL_INVALID_VALUE錯誤

clEnqueueWriteBuffer上的OpenCLCL_INVALID_VALUE錯誤

2022-04-29 01:48:30 區塊鏈

我正在嘗試使演算法在OpenCL. 我使用這個存盤庫 ( Source.cpp) 作為模板。我現在想將整個程式轉換為long演算法型別而不是float. 但我總是CL_INVALID_VALUE在第二個得到一個 (-30) 例外clEnqueueWriteBuffer我浪費了幾個小時沒有發現錯誤,所以也許我已經監督了一些明顯的事情(我還沒有對 opencl 做太多......)?

我的代碼(不作業)

#include <cassert>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include<time.h>
#include <CL/cl.h>

//#define DATA_SIZE 1024
#define DATA_SIZE 1024

using namespace std;


//$ /f/Tools/OCL_SDK_Light/lib/x86_64/opencl.lib blelloch_scan.cpp
const char* ProgramSource =
"__kernel void add(__global long *input, __global long *output, __global long *temp, int size){\n"\
"int thid = get_global_id(0); \n"\
"int offset = 1; \n"\
"printf('%d',thid); \n"\
"temp[2*thid] = input[2*thid]; \n"\
"temp[2*thid 1] = input[2*thid 1]; \n"\
"for(int d= size>>1; d>0; d >>= 1){ \n"\
"barrier(CLK_GLOBAL_MEM_FENCE); \n"\
"if(thid < d){ \n"\
"int ai = offset*(2*thid   1)-1; \n"\
"int bi = offset*(2*thid   2)-1; \n"\
"temp[bi]  = temp[ai]; } \n"\
"offset = offset*2; \n"\
"} \n"\
"temp[size-1] = 0; \n"\
"barrier(CLK_GLOBAL_MEM_FENCE); \n"\
"for(int d = 1; d<size; d *= 2){ \n"\
"offset >>= 1; barrier(CLK_GLOBAL_MEM_FENCE); \n"\
"if(thid < d) { \n"\
"int ai = offset*(2*thid 1)-1; int bi = offset*(2*thid 2)-1; \n"\
"long t = temp[ai]; temp[ai] = temp[bi]; temp[bi]  = t; }  \n"\
"} \n"\
"barrier(CLK_GLOBAL_MEM_FENCE); \n"\
"output[2*thid] = temp[2*thid]; \n"\
"output[2*thid 1] = temp[2*thid 1]; \n"\
"}\n"\
"\n";
/*
*/




int main(void)
{
    cl_context context;
    cl_context_properties properties[3];

    cl_command_queue command_queue;
    cl_kernel kernel;
    cl_program program;
    cl_int err;
    cl_uint num_platforms = 0;
    cl_platform_id* platforms;
    cl_device_id device_id;
    cl_uint num_of_devices = 0;
    cl_mem inputA, inputB, output;
    size_t global, loc;
    std::cout << "Setup \n";

    long arr[DATA_SIZE];
    long inputDataA[DATA_SIZE];
    long results[2 * DATA_SIZE];
    long  i;
    for (i = 1; i < DATA_SIZE - 1;i  )
    {
        inputDataA[i-1] = (long)i;
        arr[i-1] = (long)i;
    }
    clock_t ends;

    /* --------------------- Get platform ---------------------*/
    cl_int clResult = clGetPlatformIDs(0, NULL, &num_platforms);
    assert(clResult == CL_SUCCESS);

    platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) * num_platforms);
    clResult = clGetPlatformIDs(num_platforms, platforms, NULL);
    assert(clResult == CL_SUCCESS);
    /* --------------------- ------------ ---------------------*/


    /* --------------------- Get devices ---------------------*/
    cl_device_id* devices = NULL;
    cl_uint num_devices;

    clResult = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices);
    assert(clResult == CL_SUCCESS);

    devices = (cl_device_id*)malloc(sizeof(cl_device_id) * num_platforms);

    if (clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, num_devices, devices, NULL) != CL_SUCCESS)
    {
        printf("could not find device id");
    }
    assert(clResult == CL_SUCCESS);
    /* --------------------- ----------- ---------------------*/
    properties[0] = CL_CONTEXT_PLATFORM;
    properties[1] = 0;
    cl_int contextResult;
    context = clCreateContext(NULL, 1, &devices[0], NULL, NULL, &contextResult);
    assert(contextResult == CL_SUCCESS);
    // create command queue using the context and device
    command_queue = clCreateCommandQueueWithProperties(context, devices[0], 0, &err);

    // create a program from the kernel source code
    program = clCreateProgramWithSource(context, 1, (const char**)&ProgramSource, NULL, &err);

    // compile the program
    if (clBuildProgram(program, 0, NULL, NULL, NULL, NULL) != CL_SUCCESS)
    {
        printf("Error building program\n");
        return 1;
    }

    // specify which kernel from the program to execute
    kernel = clCreateKernel(program, "add", &err);

    // create buffers for the input and ouput
    cl_int result;
    inputA = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(long) * DATA_SIZE, NULL, NULL);
    inputB = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(long) * DATA_SIZE, NULL, NULL);
    output = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(long) * DATA_SIZE, NULL, NULL);

    // load data into the input buffer
    clResult = clEnqueueWriteBuffer(command_queue, inputA, CL_TRUE, 0, sizeof(long) * DATA_SIZE, inputDataA, 0, NULL, NULL);
    assert(clResult == CL_SUCCESS);
    clResult = clEnqueueWriteBuffer(command_queue, inputB, CL_TRUE, 0, sizeof(long) * DATA_SIZE , 0, 0, NULL, NULL);
    assert(clResult == CL_SUCCESS); // ERROR HERE 
    clResult = clEnqueueWriteBuffer(command_queue, output, CL_TRUE, 0, sizeof(long) * DATA_SIZE, 0, 0, NULL, NULL);
    assert(clResult == CL_SUCCESS);


    int temp = DATA_SIZE;

    clock_t start = clock();

    // set the argument list for the kernel command
    clResult = clSetKernelArg(kernel, 0, sizeof(cl_mem), &inputA);
    assert(clResult == CL_SUCCESS);


    clResult = clSetKernelArg(kernel, 1, sizeof(cl_mem), &output);
    assert(clResult == CL_SUCCESS);


    clResult = clSetKernelArg(kernel, 2, sizeof(cl_mem), &inputB);
    assert(clResult == CL_SUCCESS);


    clResult = clSetKernelArg(kernel, 3, sizeof(int), &temp);
    assert(clResult == CL_SUCCESS);


    global = DATA_SIZE; // num of processors
    loc = 256;

    printf("\n>> start parallel ---------- \n");
    // enqueue the kernel command for execution
    clResult = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global, &loc, 0, NULL, NULL);
    assert(clResult == CL_SUCCESS);

    // copy the results from out of the output buffer
    clResult = clEnqueueReadBuffer(command_queue, output, CL_TRUE, 0, sizeof(long) * DATA_SIZE, results, 0, NULL, NULL);
    assert(clResult == CL_SUCCESS);


    clFinish(command_queue);
    ends = clock();

    // print the results
    int k = 1;
    for (k = 1;k < 8; k  )
    {
        printf("%d - ", k);
        printf("%d \n", results[k]);
    }
    double time_taken = ((double)(ends - start)) / CLK_TCK;
    printf("\n>>finished parallel in %lf seconds\n", time_taken);

    // cleanup - release OpenCL resources

    printf("\n-------------------------------------\n");


    /* -------sequential ------- */
    printf("\n>> start sequential ---------- \n");
    long prefixSum[DATA_SIZE] = { 0 };

    const clock_t startSequential = clock();

    prefixSum[0] = arr[0];
    long idx = 1;

    for (idx = 1; idx < DATA_SIZE; idx  ) {
        prefixSum[idx] = prefixSum[idx - 1]   arr[idx];
    }
    const clock_t endSequential = clock();




    double seqTime = ((double)(endSequential - startSequential)) / CLK_TCK;

    printf("\n>> finished sequential in %lf\n", seqTime);
    for (int j = 0;j < 8; j  )
    {
        printf("%d - ", j);
        printf("%d \n", prefixSum[j]);
    }


    clReleaseMemObject(inputA);
    clReleaseMemObject(inputB);
    clReleaseMemObject(output);
    clReleaseProgram(program);
    clReleaseKernel(kernel);
    clReleaseCommandQueue(command_queue);
    clReleaseContext(context);

    return 0;
}

存盤庫代碼(作業):

#include <cassert>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include<time.h>

#include <CL/cl.h>

#define DATA_SIZE 1024
using namespace std;
ofstream outfile;


const char* ProgramSource =
"__kernel void add(__global float *input, __global float *output, __global float *temp, int size){\n"\
"int thid = get_global_id(0); \n"\
"int offset = 1; \n"\
"temp[2*thid] = input[2*thid]; \n"\
"temp[2*thid 1] = input[2*thid 1]; \n"\
"for(int d= size>>1; d>0; d >>= 1){ \n"\
"barrier(CLK_GLOBAL_MEM_FENCE); \n"\
"if(thid < d){ \n"\
"int ai = offset*(2*thid   1)-1; \n"\
"int bi = offset*(2*thid   2)-1; \n"\
"temp[bi]  = temp[ai]; } \n"\
"offset = offset*2; \n"\
"} \n"\
"temp[size-1] = 0; \n"\
"barrier(CLK_GLOBAL_MEM_FENCE); \n"\
"for(int d = 1; d<size; d *= 2){ \n"\
"offset >>= 1; barrier(CLK_GLOBAL_MEM_FENCE); \n"\
"if(thid < d) { \n"\
"int ai = offset*(2*thid 1)-1; int bi = offset*(2*thid 2)-1; \n"\
"float t = temp[ai]; temp[ai] = temp[bi]; temp[bi]  = t; }  \n"\
"} \n"\
"barrier(CLK_GLOBAL_MEM_FENCE); \n"\
"output[2*thid] = temp[2*thid]; \n"\
"output[2*thid 1] = temp[2*thid 1]; \n"\
"}\n"\
"\n";
/*
*/



int main(void)
{
    cl_uint num_platforms = 0;

    cl_context context;
    cl_context_properties properties[3];
    cl_kernel kernel;
    cl_platform_id* platforms;
    cl_command_queue command_queue;
    cl_program program;
    cl_int err;
    cl_uint num_of_platforms = 0;
    cl_platform_id platform_id;
    cl_device_id device_id;
    cl_uint num_of_devices = 0;
    cl_mem inputA, inputB, output;
    outfile.open("shubham.txt");
    size_t global, loc;

    float inputDataA[DATA_SIZE];
    float results[2 * DATA_SIZE] = { 0 };

    int i;
    for (i = 0; i < DATA_SIZE;i  )
    {
        inputDataA[i] = (float)i;
    }
    clock_t start, ends;

    /* --------------------- Get platform ---------------------*/
    cl_int clResult = clGetPlatformIDs(0, NULL, &num_platforms);
    assert(clResult == CL_SUCCESS);

    platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) * num_platforms);
    clResult = clGetPlatformIDs(num_platforms, platforms, NULL);
    assert(clResult == CL_SUCCESS);
    /* --------------------- ------------ ---------------------*/


    /* --------------------- Get devices ---------------------*/
    cl_device_id* devices = NULL;
    cl_uint num_devices;

    clResult = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices);
    assert(clResult == CL_SUCCESS);

    devices = (cl_device_id*)malloc(sizeof(cl_device_id) * num_platforms);

    if (clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, num_devices, devices, NULL) != CL_SUCCESS)
    {
        printf("could not find device id");
    }
    assert(clResult == CL_SUCCESS);
    /* --------------------- ----------- ---------------------*/
    properties[0] = CL_CONTEXT_PLATFORM;
    properties[1] = 0;
    cl_int contextResult;
    context = clCreateContext(NULL, 1, &devices[0], NULL, NULL, &contextResult);
    assert(contextResult == CL_SUCCESS);
    // create command queue using the context and device

    // create command queue using the context and device
    command_queue = clCreateCommandQueueWithProperties(context, devices[0], 0, &err);

    // create a program from the kernel source code
    program = clCreateProgramWithSource(context, 1, (const char**)&ProgramSource, NULL, &err);

    // compile the program
    if (clBuildProgram(program, 0, NULL, NULL, NULL, NULL) != CL_SUCCESS)
    {
        printf("Error building program\n");
        return 1;
    }

    // specify which kernel from the program to execute
    kernel = clCreateKernel(program, "add", &err);

    // create buffers for the input and ouput

    inputA = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float) * DATA_SIZE, NULL, NULL);
    inputB = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float) * DATA_SIZE, NULL, NULL);
    output = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float) * DATA_SIZE, NULL, NULL);

    // load data into the input buffer
    clEnqueueWriteBuffer(command_queue, inputA, CL_TRUE, 0, sizeof(float) * DATA_SIZE, inputDataA, 0, NULL, NULL);
    clEnqueueWriteBuffer(command_queue, inputB, CL_TRUE, 0, sizeof(float) * DATA_SIZE, 0, 0, NULL, NULL);
    clEnqueueWriteBuffer(command_queue, output, CL_TRUE, 0, sizeof(float) * DATA_SIZE, 0, 0, NULL, NULL);

    int temp = DATA_SIZE;

    start = clock();

    // set the argument list for the kernel command
    clResult = clSetKernelArg(kernel, 0, sizeof(cl_mem), &inputA);
    assert(clResult == CL_SUCCESS);

    clResult = clSetKernelArg(kernel, 1, sizeof(cl_mem), &output);
    assert(clResult == CL_SUCCESS);

    clResult = clSetKernelArg(kernel, 2, sizeof(cl_mem), &inputB);
    assert(clResult == CL_SUCCESS);
    clResult = clSetKernelArg(kernel, 3, sizeof(int), &temp);
    assert(clResult == CL_SUCCESS);

    global = DATA_SIZE;
    loc = 256;
    // enqueue the kernel command for execution
    clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global, &loc, 0, NULL, NULL);
    clFinish(command_queue);

    // copy the results from out of the output buffer
    clEnqueueReadBuffer(command_queue, output, CL_TRUE, 0, sizeof(float) * DATA_SIZE, results, 0, NULL, NULL);
    //clEnqueueReadBuffer(command_queue, inputB, CL_TRUE, 0, sizeof(float) *16, shubh, 0, NULL, NULL);

    // print the results
    printf("output: ");

    for (i = 0;i < 5; i  )
    {
        printf("%f \n", results[i]);
        outfile << results[i] << " ";
    }
    ends = clock();
    double time_taken = ((double)(ends - start)) / CLK_TCK;
    outfile << endl << "Time taken is : " << time_taken << endl;

    clReleaseMemObject(inputA);
    clReleaseMemObject(inputB);
    clReleaseMemObject(output);
    clReleaseProgram(program);
    clReleaseKernel(kernel);
    clReleaseCommandQueue(command_queue);
    clReleaseContext(context);
    return 0;
}

提前致謝

uj5u.com熱心網友回復:

我發現了你的錯誤。對我來說,它首先不會編譯 OpenCL C 代碼,所以我用

char info[1024];
clGetProgramBuildInfo(program, devices[0], CL_PROGRAM_BUILD_LOG, 1024*sizeof(char), (void*)info, NULL); // print build log
printf(info);

獲取構建日志:

<kernel>:4:8: warning: multi-character character constant
printf('0',thid);
       ^
<kernel>:4:8: warning: incompatible integer to pointer conversion passing 'int' to parameter of type '__constant char *'
printf('190',thid);
       ^~~~
cl_kernel.h:4694:32: note: passing argument to parameter here
printf(constant char * restrict, ...) __asm("llvm.nvvm.internal.printf.cl");

似乎'不是\"問題。更改此行:

"printf(\"%d\",thid); \n"

然后 OpenCL C 代碼編譯,我可以重現 CL_INVALID_VALUE 錯誤。

這是問題所在:您使用clEnqueueWriteBuffer將資料從復制inputB0. 您需要添加 C 陣列以將資料復制到:

long inputDataA[DATA_SIZE];
long inputDataB[DATA_SIZE];
long outputData[DATA_SIZE];

clResult = clEnqueueWriteBuffer(command_queue, inputA, CL_TRUE, 0, sizeof(long) * DATA_SIZE, inputDataA, 0, NULL, NULL);
assert(clResult == CL_SUCCESS);
clResult = clEnqueueWriteBuffer(command_queue, inputB, CL_TRUE, 0, sizeof(long) * DATA_SIZE, inputDataB, 0, NULL, NULL);
assert(clResult == CL_SUCCESS); // WORKS NOW
clResult = clEnqueueWriteBuffer(command_queue, output, CL_TRUE, 0, sizeof(long) * DATA_SIZE, outputData, 0, NULL, NULL);
assert(clResult == CL_SUCCESS);

然后它作業,我得到這個輸出:

Setup
0

>> start parallel ----------
25625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035101234567891011121314151617181920212223242526272829303138438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441564656667686970717273747576777879808182838485868788899091929394953523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823839697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612741641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863932333435363738394041424344454647484950515253545556575859606162634484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784798328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628635445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745751921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222234804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105118648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948955125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425431281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581598008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308315765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066072242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542559609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909916406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706711601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901917687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987997367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667679929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210236726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027039289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589597047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347358968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269271 - 0
2 - 1
3 - 2
4 - 4
5 - 6
6 - 9
7 - 12

>>finished parallel in 0.023000 seconds

-------------------------------------

>> start sequential ----------

>> finished sequential in 0.000000
0 - 1
1 - 3
2 - 6
3 - 10
4 - 15
5 - 21
6 - 28
7 - 36

另請注意,無論出于何種愚蠢的原因,在 OpenCL C 中,long= 64 位整數,但在 C 中,long=“至少”32 位整數。在 C 中,您應該使用long long int它,因為這始終是 64 位整數。例如typedef int64_t slong;,您可以使用 whereint64_t本身是long long int.

另一個問題是程式不是確定性的。多次執行時,每次都會得到不同的結果。必須存在一些競爭條件。我想你錯誤地認為它barrier(CLK_GLOBAL_MEM_FENCE);提供了所有執行緒的全域同步,但事實并非如此。唯一的全域同步是在所需的同步點將內核拆分為多個內核,并一個接一個地執行它們。


最后,為了使 C 中的 OpenCL 開發更容易,并防止在這些簡單的錯誤上浪費時間,我創建了一個輕量級的OpenCL-Wrapper來消除所有 OpenCL 代碼開銷。這樣,您的代碼將縮短 4 倍,并且更易于理解:

#include "opencl.hpp"

#define DATA_SIZE 1024

int main() {
    Clock clock;
    clock.start();

    Device device(select_device_with_most_flops()); // compile OpenCL C code for the fastest available device

    Memory<slong> arr(device, DATA_SIZE, 1u, true, false);
    Memory<slong> inputA(device, DATA_SIZE);
    Memory<slong> inputB(device, DATA_SIZE);
    Memory<slong> output(device, DATA_SIZE);

    for(int i=1; i<DATA_SIZE-1; i  ) {
        inputA[i-1] = (slong)i;
        arr[i-1] = (slong)i;
    }
    inputA.write_to_device();
    
    Kernel kernel(device, DATA_SIZE, "add", inputA, output, inputB);
    kernel.add_constants(DATA_SIZE);

    kernel.run();
    output.read_from_device();

    double time_taken = clock.stop();

    // print the results
    for(int k=1; k<8; k  ) {
        printf("%d - ", k);
        printf("%d \n", output[k]);
    }
    printf("\n>>finished parallel in %lf seconds\n", time_taken);
    printf("\n-------------------------------------\n");
    printf("\n>> start sequential ---------- \n");
    long prefixSum[DATA_SIZE] = { 0 };

    clock.start();
    prefixSum[0] = arr[0];
    for(long idx=1; idx<DATA_SIZE; idx  ) {
        prefixSum[idx] = prefixSum[idx-1] arr[idx];
    }
    double seqTime = clock.stop();

    printf("\n>> finished sequential in %lf\n", seqTime);
    for(int j=0; j<8; j  ) {
        printf("%d - ", j);
        printf("%d \n", prefixSum[j]);
    }

    wait();
    return 0;
}
#include "kernel.hpp" // note: unbalanced round brackets () are not allowed and string literals can't be arbitrarily long, so periodically interrupt with ) R(
string opencl_c_container() { return R( // ########################## begin of OpenCL C code ####################################################################

kernel void add(__global long* input, __global long* output, __global long* temp, int size) {
    int thid = get_global_id(0);
    int offset = 1;
    printf("%d",thid);
    temp[2*thid] = input[2*thid];
    temp[2*thid 1] = input[2*thid 1];
    for(int d= size>>1; d>0; d >>= 1) {
        barrier(CLK_GLOBAL_MEM_FENCE);
        if(thid < d) {
            int ai = offset*(2*thid   1)-1;
            int bi = offset*(2*thid   2)-1;
            temp[bi]  = temp[ai];
        }
        offset = offset*2;
    }
    temp[size-1] = 0;
    barrier(CLK_GLOBAL_MEM_FENCE);
    for(int d = 1; d<size; d *= 2) {
        offset >>= 1; barrier(CLK_GLOBAL_MEM_FENCE);
        if(thid < d) {
            int ai = offset*(2*thid 1)-1; int bi = offset*(2*thid 2)-1;
            long t = temp[ai]; temp[ai] = temp[bi]; temp[bi]  = t;
        }
    }
    barrier(CLK_GLOBAL_MEM_FENCE);
    output[2*thid] = temp[2*thid];
    output[2*thid 1] = temp[2*thid 1];
}

);} // ############################################################### end of OpenCL C code #####################################################################

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/466751.html

標籤:C 算法 开放式

上一篇:調整Floyd-Warshall演算法以檢測周期

下一篇:兩組頂點之間的最短路徑

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • JAVA使用 web3j 進行token轉賬

    最近新學習了下區塊鏈這方面的知識,所學不多,給大家分享下。 # 1. 關于web3j web3j是一個高度模塊化,反應性,型別安全的Java和Android庫,用于與智能合約配合并與以太坊網路上的客戶端(節點)集成。 # 2. 準備作業 jdk版本1.8 引入maven <dependency> < ......

    uj5u.com 2020-09-10 03:03:06 more
  • 以太坊智能合約開發框架Truffle

    前言 部署智能合約有多種方式,命令列的瀏覽器的渠道都有,但往往跟我們程式員的風格不太相符,因為我們習慣了在IDE里寫了代碼然后打包運行看效果。 雖然現在IDE中已經存在了Solidity插件,可以撰寫智能合約,但是部署智能合約卻要另走他路,沒辦法進行一個快捷的部署與測驗。 如果團隊管理的區塊節點多、 ......

    uj5u.com 2020-09-10 03:03:12 more
  • 谷歌二次驗證碼成為區塊鏈專用安全碼,你怎么看?

    前言 谷歌身份驗證器,前些年大家都比較陌生,但隨著國內互聯網安全的加強,它越來越多地出現在大家的視野中。 比較廣泛接觸的人群是國際3A游戲愛好者,游戲盜號現象嚴重+國外賬號安全應用廣泛,這類游戲一般都會要求用戶系結名為“兩步驗證”、“雙重驗證”等,平臺一般都推薦用谷歌身份驗證器。 后來區塊鏈業務風靡 ......

    uj5u.com 2020-09-10 03:03:17 more
  • 密碼學DAY1

    目錄 ##1.1 密碼學基本概念 密碼在我們的生活中有著重要的作用,那么密碼究竟來自何方,為何會產生呢? 密碼學是網路安全、資訊安全、區塊鏈等產品的基礎,常見的非對稱加密、對稱加密、散列函式等,都屬于密碼學范疇。 密碼學有數千年的歷史,從最開始的替換法到如今的非對稱加密演算法,經歷了古典密碼學,近代密 ......

    uj5u.com 2020-09-10 03:03:50 more
  • 密碼學DAY1_02

    目錄 ##1.1 ASCII編碼 ASCII(American Standard Code for Information Interchange,美國資訊交換標準代碼)是基于拉丁字母的一套電腦編碼系統,主要用于顯示現代英語和其他西歐語言。它是現今最通用的單位元組編碼系統,并等同于國際標準ISO/IE ......

    uj5u.com 2020-09-10 03:04:50 more
  • 密碼學DAY2

    ##1.1 加密模式 加密模式:https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html ECB ECB : Electronic codebook, 電子密碼本. 需要加密的訊息按照塊密碼的塊大小被分為數個塊,并對每個塊進 ......

    uj5u.com 2020-09-10 03:05:42 more
  • NTP時鐘服務器的特點(京準電子)

    NTP時鐘服務器的特點(京準電子) NTP時鐘服務器的特點(京準電子) 京準電子官V——ahjzsz 首先對時間同步進行了背景介紹,然后討論了不同的時間同步網路技術,最后指出了建立全球或區域時間同步網存在的問題。 一、概 述 在通信領域,“同步”概念是指頻率的同步,即網路各個節點的時鐘頻率和相位同步 ......

    uj5u.com 2020-09-10 03:05:47 more
  • 標準化考場時鐘同步系統推進智能化校園建設

    標準化考場時鐘同步系統推進智能化校園建設 標準化考場時鐘同步系統推進智能化校園建設 安徽京準電子科技官微——ahjzsz 一、背景概述隨著教育事業的快速發展,學校建設如雨后春筍,隨之而來的學校教育、管理、安全方面的問題成了學校管理人員面臨的最大的挑戰,這些問題同時也是學生家長所擔心的。為了讓學生有更 ......

    uj5u.com 2020-09-10 03:05:51 more
  • 位元幣入門

    引言 位元幣基本結構 位元幣基礎知識 1)哈希演算法 2)非對稱加密技術 3)數字簽名 4)MerkleTree 5)哪有位元幣,有的是UTXO 6)位元幣挖礦與共識 7)區塊驗證(共識) 總結 引言 上一篇我們已經知道了什么是區塊鏈,此篇說一下區塊鏈的第一個應用——位元幣。其實先有位元幣,后有的區塊 ......

    uj5u.com 2020-09-10 03:06:15 more
  • 北斗對時服務器(北斗對時設備)電力系統應用

    北斗對時服務器(北斗對時設備)電力系統應用 北斗對時服務器(北斗對時設備)電力系統應用 京準電子科技官微(ahjzsz) 中國北斗衛星導航系統(英文名稱:BeiDou Navigation Satellite System,簡稱BDS),因為是目前世界范圍內唯一可以大面積提供免費定位服務的系統,所以 ......

    uj5u.com 2020-09-10 03:06:20 more
最新发布
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:46:47 more
  • Hyperledger Fabric 使用 CouchDB 和復雜智能合約開發

    在上個實驗中,我們已經實作了簡單智能合約實作及客戶端開發,但該實驗中智能合約只有基礎的增刪改查功能,且其中的資料管理功能與傳統 MySQL 比相差甚遠。本文將在前面實驗的基礎上,將 Hyperledger Fabric 的默認資料庫支持 LevelDB 改為 CouchDB 模式,以實作更復雜的資料... ......

    uj5u.com 2023-04-16 07:28:31 more
  • .NET Core 波場鏈離線簽名、廣播交易(發送 TRX和USDT)筆記

    Get Started NuGet You can run the following command to install the Tron.Wallet.Net in your project. PM> Install-Package Tron.Wallet.Net 配置 public reco ......

    uj5u.com 2023-04-14 08:08:00 more
  • DKP 黑客分析——不正確的代幣對比率計算

    概述: 2023 年 2 月 8 日,針對 DKP 協議的閃電貸攻擊導致該協議的用戶損失了 8 萬美元,因為 execute() 函式取決于 USDT-DKP 對中兩種代幣的余額比率。 智能合約黑客概述: 攻擊者的交易:0x0c850f,0x2d31 攻擊者地址:0xF38 利用合同:0xf34ad ......

    uj5u.com 2023-04-07 07:46:09 more
  • Defi開發簡介

    Defi開發簡介 介紹 Defi是去中心化金融的縮寫, 是一項旨在利用區塊鏈技術和智能合約創建更加開放,可訪問和透明的金融體系的運動. 這與傳統金融形成鮮明對比,傳統金融通常由少數大型銀行和金融機構控制 在Defi的世界里,用戶可以直接從他們的電腦或移動設備上訪問廣泛的金融服務,而不需要像銀行或者信 ......

    uj5u.com 2023-04-05 08:01:34 more
  • solidity簡單的ERC20代幣實作

    // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; import "hardhat/console.sol"; //ERC20 同質化代幣,每個代幣的本質或性質都是相同 //ETH 是原生代幣,它不是ERC20代幣, ......

    uj5u.com 2023-03-21 07:56:29 more
  • solidity 參考型別修飾符memory、calldata與storage 常量修飾符C

    在solidity語言中 參考型別修飾符(參考型別為存盤空間不固定的數值型別) memory、calldata與storage,它們只能修飾參考型別變數,比如字串、陣列、位元組等... memory 適用于方法傳參、返參或在方法體內使用,使用完就會清除掉,釋放記憶體 calldata 僅適用于方法傳參 ......

    uj5u.com 2023-03-08 07:57:54 more
  • solidity注解標簽

    在solidity語言中 注釋符為// 注解符為/* 內容*/ 或者 是 ///內容 注解中含有這幾個標簽給予我們使用 @title 一個應該描述合約/介面的標題 contract, library, interface @author 作者的名字 contract, library, interf ......

    uj5u.com 2023-03-08 07:57:49 more
  • 評價指標:相似度、GAS消耗

    【代碼注釋自動生成方法綜述】 這些評測指標主要來自機器翻譯和文本總結等研究領域,可以評估候選文本(即基于代碼注釋自動方法而生成)和參考文本(即基于手工方式而生成)的相似度. BLEU指標^[^?88^^?^]^:其全稱是bilingual evaluation understudy.該指標是最早用于 ......

    uj5u.com 2023-02-23 07:27:39 more
  • 基于NOSTR協議的“公有制”版本的Twitter,去中心化社交軟體Damus

    最近,一個幽靈,Web3的幽靈,在網路游蕩,它叫Damus,這玩意詮釋了什么叫做病毒式營銷,滑稽的是,一個Web3產品卻在Web2的產品鏈上瘋狂傳銷,各方大佬紛紛為其背書,到底發生了什么?Damus的葫蘆里,賣的是什么藥? 注冊和簡單實用 很少有什么產品在用戶注冊環節會有什么噱頭,但Damus確實出 ......

    uj5u.com 2023-02-05 06:48:39 more