F
Furtano
Gast
Hallo,
ich bekomme folgenden Fehler in Visual Studio 2012 angezeigt, versteh nicht woran es liegt
.

Danke und LG,
Furtano
ich bekomme folgenden Fehler in Visual Studio 2012 angezeigt, versteh nicht woran es liegt


Danke und LG,
Furtano
PHP:
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#ifdef __APPLE__
#include "OpenCL/opencl.h"
#else
#include "CL/cl.hpp"
#endif
const int LIST_SIZE = 1000;
std::string GetPlatformName (cl_platform_id id)
{
size_t size = 0;
clGetPlatformInfo (id, CL_PLATFORM_NAME, 0, nullptr, &size);
std::string result;
result.resize (size);
clGetPlatformInfo (id, CL_PLATFORM_NAME, size,
const_cast<char*> (result.data ()), nullptr);
return result;
}
std::string GetDeviceName (cl_device_id id)
{
size_t size = 0;
clGetDeviceInfo (id, CL_DEVICE_NAME, 0, nullptr, &size);
std::string result;
result.resize (size);
clGetDeviceInfo (id, CL_DEVICE_NAME, size,
const_cast<char*> (result.data ()), nullptr);
return result;
}
void CheckError (cl_int error)
{
if (error != CL_SUCCESS) {
std::cerr << "OpenCL call failed with error " << error << std::endl;
std::exit (1);
}
}
std::string LoadKernel (const char* name)
{
std::ifstream in (name);
std::string result (
(std::istreambuf_iterator<char> (in)),
std::istreambuf_iterator<char> ());
return result;
}
cl_program CreateProgram (const std::string& source,
cl_context context)
{
// http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateProgramWithSource.html
size_t lengths [1] = { source.size () };
const char* sources [1] = { source.data () };
cl_int error = 0;
cl_program program = clCreateProgramWithSource (context, 1, sources, lengths, &error);
CheckError (error);
return program;
}
int main ()
{
/**
GET DEVICE
**/
// http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html
cl_uint platformIdCount = 0;
clGetPlatformIDs (0, nullptr, &platformIdCount);
if (platformIdCount == 0) {
std::cerr << "No OpenCL platform found" << std::endl;
return 1;
} else {
std::cout << "Found " << platformIdCount << " platform(s)" << std::endl;
}
std::vector<cl_platform_id> platformIds (platformIdCount);
clGetPlatformIDs (platformIdCount, platformIds.data (), nullptr);
for (cl_uint i = 0; i < platformIdCount; ++i) {
std::cout << "\t (" << (i+1) << ") : " << GetPlatformName (platformIds [i]) << std::endl;
}
// http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceIDs.html
cl_uint deviceIdCount = 0;
clGetDeviceIDs (platformIds [0], CL_DEVICE_TYPE_ALL, 0, nullptr,
&deviceIdCount);
if (deviceIdCount == 0) {
std::cerr << "No OpenCL devices found" << std::endl;
return 1;
} else {
std::cout << "Found " << deviceIdCount << " device(s)" << std::endl;
}
std::vector<cl_device_id> deviceIds (deviceIdCount);
clGetDeviceIDs (platformIds [0], CL_DEVICE_TYPE_ALL, deviceIdCount,
deviceIds.data (), nullptr);
for (cl_uint i = 0; i < deviceIdCount; ++i) {
std::cout << "\t (" << (i+1) << ") : " << GetDeviceName (deviceIds [i]) << std::endl;
}
// http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html
const cl_context_properties contextProperties [] =
{
CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties> (platformIds [0]),
0, 0
};
cl_int error = CL_SUCCESS;
cl_context context = clCreateContext (contextProperties, deviceIdCount,
deviceIds.data (), nullptr, nullptr, &error);
CheckError (error);
std::cout << "Context created" << std::endl;
int a;
std::cin >> a;
unsigned int n = 1000;
double *h_a;
double *h_b;
double *h_c;
// Device input buffers
cl::Buffer d_a;
cl::Buffer d_b;
// Device output buffer
cl::Buffer d_c;
h_a = new double[n];
h_b = new double[n];
h_c = new double[n];
// Size, in bytes, of each vector
size_t bytes = n*sizeof(double);
// Initialize vectors on host
for(int i = 0; i < n; i++ )
{
h_a[i] = sinf(i)*sinf(i);
h_b[i] = cosf(i)*cosf(i);
}
// Create a program from source
cl_program program = CreateProgram (LoadKernel ("kernels/image.cl"),
context);
CheckError (clBuildProgram (program, deviceIdCount, deviceIds.data (),
"-D FILTER_SIZE=1", nullptr, nullptr));
// http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernel.html
cl_kernel kernel = clCreateKernel (program, "vec_add", &error);
CheckError (error);
// Create a buffer for the filter weights
// http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html
cl_mem filterWeightsBuffer = clCreateBuffer (context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
sizeof (float) * 9, a, &error);
CheckError (error);
// Setup the kernel arguments
clSetKernelArg (kernel, 0, sizeof (cl_mem), &d_a);
clSetKernelArg (kernel, 1, sizeof (cl_mem), &d_b);
clSetKernelArg (kernel, 2, sizeof (cl_mem), &d_c);
// http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateCommandQueue.html
cl_command_queue queue = clCreateCommandQueue (context, deviceIds [0],
0, &error);
CheckError (error);
cl::Buffer bufferA = cl::Buffer(context, CL_MEM_READ_ONLY, LIST_SIZE * sizeof(int));
cl::Buffer bufferB = cl::Buffer(context, CL_MEM_READ_ONLY, LIST_SIZE * sizeof(int));
cl::Buffer bufferC = cl::Buffer(context, CL_MEM_WRITE_ONLY, LIST_SIZE * sizeof(int));
}