1

您好,我正在尝试使用 DPC++ 并行化我的两个循环,但它给出了 LLVM 错误:SPIRV 内部错误。不知道为什么,各位大神能帮我解决一下问题吗?

https://simplecore-ger.intel.com/techdecoded/wp-content/uploads/sites/11/Webinar-Slides-DPC-Part-1-An-Introduction-to-the-New-Programming-Model-.pdf

https://simplecore-ger.intel.com/techdecoded/wp-content/uploads/sites/11/Webinar-Slides-DPC-Part-2-Programming-Best-Practices.pdf

char* rsa_decrypt_without_private_key(const long long* message, const unsigned long message_size, const struct public_key_class* pub)
{
    struct private_key_class unknownpriv[1];
    long long p, q, phi_max, e, d;
    p = public_prime;
    q = pub->modulus / p;
    phi_max = (p - 1) * (q - 1);
    e = powl(2, 8) + 1;
    d = ExtEuclid(phi_max, e);
    while (d < 0) {
        d = d + phi_max;
    }
    unknownpriv->modulus = pub->modulus;
    unknownpriv->exponent = d;

    if (message_size % sizeof(long long) != 0) {
        fprintf(stderr, "Error: message_size is not divisible by %d, so cannot be output of rsa_encrypt\n", (int)sizeof(long long));
        return NULL;
    }
    
    char* decrypted = (char*) malloc(message_size / sizeof(long long));
    
    char* temp = (char*) malloc(message_size);
    if ((decrypted == NULL) || (temp == NULL)) {
        fprintf(stderr, "Error: Heap allocation failed.\n");
        return NULL;
    }

    buffer<char, 1> A(decrypted, range<1>{ message_size / sizeof(long long)});
    buffer<char, 1> B(temp, range<1>{ message_size });
    auto R = range<1>{ message_size / 8 };
    queue z;

    z.submit([&](handler& h) {
        auto out = B.get_access<access::mode::write>(h);
        h.parallel_for(R, [=](id<1> i) {
            out[i] = rsa_modExp(message[i], unknownpriv->exponent, unknownpriv->modulus);
        });
    });


    z.submit([&](handler& h) {
        auto out = A.get_access<access::mode::write>(h);
        auto in = B.get_access<access::mode::read>(h);
        h.parallel_for(R, [=](id<1> i) {
            out[i] = in[i];
        });
    });
    
    /*
    for (i = 0; i < message_size / 8; i++) {
        temp[i] = rsa_modExp(message[i], unknownpriv->exponent, unknownpriv->modulus);
    }

    for (i = 0; i < message_size / 8; i++) {
        decrypted[i] = temp[i];
    }*/

    free(temp);
    return decrypted;
}
4

1 回答 1

0

当您尝试在 parallel_for 内核中调用函数(rsa_modExp)时,您需要确保该函数存在于同一个翻译单元中。

当我们想要调用内核中定义在不同翻译单元中的函数时,这些函数需要用SYCL_EXTERNAL标记。如果没有这个属性,编译器将只编译一个在设备代码之外使用的函数(使得从设备代码中调用该外部函数是非法的)。

链接到 DPC++ 书籍以供进一步参考: https ://www.apress.com/us/book/9781484255735 (第 13 章)

于 2021-04-08T08:13:48.187 回答