再会,
我有一个 openCL 内核,它使用莱布尼茨公式来计算 pi。目前我的问题是我得到的值不是 pi,而是 4。
__kernel void calculatePi(int numIterations, __global float *outputPi,
__local float* local_result, int numWorkers)
{
__private const uint gid = get_global_id(0);
__private const uint lid = get_local_id(0);
__private const uint offset = numIterations*gid*2;
__private float sum = 0.0f;
// Have the first worker initialize local_result
if (gid == 0)
{
for (int i = 0; i < numWorkers; i++)
{
local_result[i] = 0.0f;
}
}
// Have all workers wait until this is completed
barrier(CLK_GLOBAL_MEM_FENCE); …Run Code Online (Sandbox Code Playgroud) 晚上好(感恩节快乐),
我有以下代码(从我的主代码中摘录到一个独立的文件中),并且收到一些我想解决的警告消息。
这是代码:
#include <cassert>
#include <ostream>
#include <climits>
#include <iostream>
#include <string>
using namespace std;
class WordCount
{
public:
// Constructors
WordCount() : word(""), count(0) { }
WordCount(string theWord, unsigned theCount = 1) : word(theWord), count(theCount) { }
// Accessors
string Word() const { return word; }
unsigned Count() const { return count; }
// Mutator
void Update() { ++count; }
// Output a Word to a stream.
void Show(ostream &os) { os << word << "=" << count; …Run Code Online (Sandbox Code Playgroud)