本文整理汇总了C++中scoped_array::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ scoped_array::reset方法的具体用法?C++ scoped_array::reset怎么用?C++ scoped_array::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scoped_array
的用法示例。
在下文中一共展示了scoped_array::reset方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init_problem
// Initialize the data for the problem. Requires num_devices to be known.
void init_problem() {
if(num_devices == 0) {
checkError(-1, "No devices");
}
input_a.reset(num_devices);
input_b.reset(num_devices);
output.reset(num_devices);
ref_output.reset(num_devices);
// Generate input vectors A and B and the reference output consisting
// of a total of N elements.
// We create separate arrays for each device so that each device has an
// aligned buffer.
for(unsigned i = 0; i < num_devices; ++i) {
input_a[i].reset(n_per_device[i]);
input_b[i].reset(n_per_device[i]);
output[i].reset(n_per_device[i]);
ref_output[i].reset(n_per_device[i]);
for(unsigned j = 0; j < n_per_device[i]; ++j) {
input_a[i][j] = rand_float();
input_b[i][j] = rand_float();
ref_output[i][j] = input_a[i][j] + input_b[i][j];
}
}
}
示例2: LCSLength
void LCSLength( scoped_array<scoped_array<size_t> >& C ,vector_start_at_zero<SgNode*>& A, vector_start_at_zero<SgNode*>& B )
{
int m = A.size()+1;
int n = B.size()+1;
C.reset(new scoped_array<size_t>[m]);
for (int i = 0 ; i < m; i++)
C[i].reset(new size_t[n]);
for (size_t i = 0 ; i <= A.size() ; i++)
C[i][0]=0;
for (size_t i = 0 ; i <= B.size() ; i++)
C[0][i]=0;
for (size_t i = 1 ; i <= A.size() ; i++)
for (size_t j = 1 ; j <= B.size() ; j++)
{
if(isEqual(A[i],B[j]))
C[i][j] = C[i-1][j-1]+1;
else
C[i][j] = C[i][j-1] > C[i-1][j] ? C[i][j-1] : C[i-1][j];
}
}
示例3: WriteConsoleInput
void ConsoleHandler::WriteConsoleInput(HANDLE hStdIn, scoped_array<INPUT_RECORD>& consoleInputs, size_t& consoleInputCount, size_t maxConsoleInputCount)
{
if (consoleInputCount > 0)
{
DWORD dwTextWritten = 0;
::WriteConsoleInput(hStdIn, consoleInputs.get(), static_cast<DWORD>(consoleInputCount), &dwTextWritten);
}
if (maxConsoleInputCount > 0)
{
consoleInputs.reset(new INPUT_RECORD[maxConsoleInputCount]);
::ZeroMemory(consoleInputs.get(), sizeof(INPUT_RECORD)*maxConsoleInputCount);
}
else
{
consoleInputs.reset();
}
consoleInputCount = 0;
}
示例4: init_problem
// Initialize the data for the problem. Requires num_devices to be known.
void init_problem() {
if(num_devices == 0) {
checkError(-1, "No devices");
}
printf("Generating input matrices\n");
input_a.reset(num_devices);
output.reset(num_devices);
for(unsigned i = 0; i < num_devices; ++i) {
input_a[i].reset(A_height * A_width);
output[i].reset(C_height * C_width);
// printf("array A elements\n");
for(unsigned j = 0; j < A_height * A_width; ++j) {
if(((j%1028)==0) || ((j%1028)>=1025) || ((j/1028)==0) || (j/1028)==1025) {
input_a[i][j] = 0.0f;
}
else {
input_a[i][j] = rand_float();
}
}
}
}
示例5: compute_reference
void compute_reference() {
// Compute the reference output.
printf("Computing reference output\n");
ref_output.reset(C_height * C_width);
for(unsigned y = 0; y < C_height; ++y) {
for(unsigned x = 0; x < C_width; ++x) {
float sum = 0.0f;
if(y>=1 && x>=1 && x<=1024)
sum = 0.2*(input_a[0][(y)*A_width+x] + input_a[0][(y-1)*A_width+x] + input_a[0][(y+1)*A_width+x] + input_a[0][(y)*A_width+x-1] + input_a[0][(y)*A_width+x+1]);
ref_output[y*1028+x] = sum;
}
}
}
示例6: compute_reference
void compute_reference() {
// Compute the reference output.
printf("Computing reference output\n");
ref_output.reset(C_height * C_width);
for(unsigned y = 0, dev_index = 0; y < C_height; ++dev_index) {
for(unsigned yy = 0; yy < rows_per_device[dev_index]; ++yy, ++y) {
for(unsigned x = 0; x < C_width; ++x) {
// Compute result for C(y, x)
float sum = 0.0f;
for(unsigned k = 0; k < A_width; ++k) {
sum += input_a[dev_index][yy * A_width + k] * input_b[k * B_width + x];
}
ref_output[y * C_width + x] = sum;
}
}
}
}
示例7: loadFileData
bool loadFileData(const boost::filesystem::path& path,
scoped_array<char>& fileData,
int& fileSize) {
fs::ifstream ifs(path, ifstream::in | ifstream::binary);
if (!ifs) {
ostringstream oss;
oss << "Could not open file \"" << path << "\".";
throw rlvm::Exception(oss.str());
}
ifs.seekg(0, ios::end);
fileSize = ifs.tellg();
ifs.seekg(0, ios::beg);
fileData.reset(new char[fileSize]);
ifs.read(fileData.get(), fileSize);
return !ifs.good();
}
示例8: init_problem
// Initialize the data for the problem. Requires num_devices to be known.
void init_problem() {
if(num_devices == 0) {
checkError(-1, "No devices");
}
// Generate input matrices A and B. For matrix A, we divide up the host
// buffers so that the buffers are aligned for each device. The whole of
// matrix B is used by each device, so it does not need to be divided.
printf("Generating input matrices\n");
input_a.reset(num_devices);
output.reset(num_devices);
#if USE_SVM_API == 0
for(unsigned i = 0; i < num_devices; ++i) {
input_a[i].reset(rows_per_device[i] * A_width);
output[i].reset(rows_per_device[i] * C_width);
for(unsigned j = 0; j < rows_per_device[i] * A_width; ++j) {
input_a[i][j] = rand_float();
}
}
input_b.reset(B_height * B_width);
for(unsigned i = 0; i < B_height * B_width; ++i) {
input_b[i] = rand_float();
}
#else
for(unsigned i = 0; i < num_devices; ++i) {
input_a[i].reset(context, rows_per_device[i] * A_width);
output[i].reset(context, rows_per_device[i] * C_width);
cl_int status;
status = clEnqueueSVMMap(queue[i], CL_TRUE, CL_MAP_WRITE,
(void *)input_a[i], rows_per_device[i] * A_width * sizeof(float), 0, NULL, NULL);
checkError(status, "Failed to map input A");
for(unsigned j = 0; j < rows_per_device[i] * A_width; ++j) {
input_a[i][j] = rand_float();
}
status = clEnqueueSVMUnmap(queue[i], (void *)input_a[i], 0, NULL, NULL);
checkError(status, "Failed to unmap input A");
}
input_b.reset(context, B_height * B_width);
cl_int status;
for (unsigned i = 0; i < num_devices; ++i) {
status = clEnqueueSVMMap(queue[i], CL_TRUE, CL_MAP_WRITE,
(void *)input_b, B_height * B_width * sizeof(float), 0, NULL, NULL);
checkError(status, "Failed to map input B");
}
for(unsigned i = 0; i < B_height * B_width; ++i) {
input_b[i] = rand_float();
}
for (unsigned i = 0; i < num_devices; ++i) {
status = clEnqueueSVMUnmap(queue[i], (void *)input_b, 0, NULL, NULL);
checkError(status, "Failed to unmap input B");
}
#endif /* USE_SVM_API == 0 */
}
示例9: init_opencl
// Initializes the OpenCL objects.
bool init_opencl() {
cl_int status;
printf("Initializing OpenCL\n");
if(!setCwdToExeDir()) {
return false;
}
// Get the OpenCL platform.
platform = findPlatform("Intel(R) FPGA SDK for OpenCL(TM)");
if(platform == NULL) {
printf("ERROR: Unable to find Intel(R) FPGA OpenCL platform.\n");
return false;
}
// Query the available OpenCL device.
device.reset(getDevices(platform, CL_DEVICE_TYPE_ALL, &num_devices));
printf("Platform: %s\n", getPlatformName(platform).c_str());
printf("Using %d device(s)\n", num_devices);
for(unsigned i = 0; i < num_devices; ++i) {
printf(" %s\n", getDeviceName(device[i]).c_str());
}
// Create the context.
context = clCreateContext(NULL, num_devices, device, &oclContextCallback, NULL, &status);
checkError(status, "Failed to create context");
// Create the program for all device. Use the first device as the
// representative device (assuming all device are of the same type).
std::string binary_file = getBoardBinaryFile("matrix_mult", device[0]);
printf("Using AOCX: %s\n", binary_file.c_str());
program = createProgramFromBinary(context, binary_file.c_str(), device, num_devices);
// Build the program that was just created.
status = clBuildProgram(program, 0, NULL, "", NULL, NULL);
checkError(status, "Failed to build program");
// Create per-device objects.
queue.reset(num_devices);
kernel.reset(num_devices);
rows_per_device.reset(num_devices);
#if USE_SVM_API == 0
input_a_buf.reset(num_devices);
input_b_buf.reset(num_devices);
output_buf.reset(num_devices);
#endif /* USE_SVM_API == 0 */
const unsigned num_block_rows = C_height / BLOCK_SIZE;
for(unsigned i = 0; i < num_devices; ++i) {
// Command queue.
queue[i] = clCreateCommandQueue(context, device[i], CL_QUEUE_PROFILING_ENABLE, &status);
checkError(status, "Failed to create command queue");
// Kernel.
const char *kernel_name = "matrixMult";
kernel[i] = clCreateKernel(program, kernel_name, &status);
checkError(status, "Failed to create kernel");
// Determine the number of rows processed by this device.
// First do this computation in block-rows.
rows_per_device[i] = num_block_rows / num_devices; // this is the number of block-rows
// Spread out the remainder of the block-rows over the first
// N % num_devices.
if(i < (num_block_rows % num_devices)) {
rows_per_device[i]++;
}
// Multiply by BLOCK_SIZE to get the actual number of rows.
rows_per_device[i] *= BLOCK_SIZE;
#if USE_SVM_API == 0
// Input buffers.
// For matrix A, each device only needs the rows corresponding
// to the rows of the output matrix. We specifically
// assign this buffer to the first bank of global memory.
input_a_buf[i] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_CHANNEL_1_INTELFPGA,
rows_per_device[i] * A_width * sizeof(float), NULL, &status);
checkError(status, "Failed to create buffer for input A");
// For matrix B, each device needs the whole matrix. We specifically
// assign this buffer to the second bank of global memory.
input_b_buf[i] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_CHANNEL_2_INTELFPGA,
B_height * B_width * sizeof(float), NULL, &status);
checkError(status, "Failed to create buffer for input B");
// Output buffer. This is matrix C, for the rows that are computed by this
// device. We assign this buffer to the first bank of global memory,
// although it is not material to performance to do so because
// the reads from the input matrices are far more frequent than the
// write to the output matrix.
output_buf[i] = clCreateBuffer(context, CL_MEM_WRITE_ONLY | CL_CHANNEL_1_INTELFPGA,
rows_per_device[i] * C_width * sizeof(float), NULL, &status);
checkError(status, "Failed to create buffer for output");
#else
cl_device_svm_capabilities caps = 0;
//.........这里部分代码省略.........
示例10: init_opencl
// Initializes the OpenCL objects.
bool init_opencl() {
cl_int status;
printf("Initializing OpenCL\n");
if(!setCwdToExeDir()) {
return false;
}
// Get the OpenCL platform.
platform = findPlatform("Altera");
if(platform == NULL) {
printf("ERROR: Unable to find Altera OpenCL platform.\n");
return false;
}
// Query the available OpenCL device.
device.reset(getDevices(platform, CL_DEVICE_TYPE_ALL, &num_devices));
printf("Platform: %s\n", getPlatformName(platform).c_str());
printf("Using %d device(s)\n", num_devices);
for(unsigned i = 0; i < num_devices; ++i) {
printf(" %s\n", getDeviceName(device[i]).c_str());
}
// Create the context.
context = clCreateContext(NULL, num_devices, device, NULL, NULL, &status);
checkError(status, "Failed to create context");
// Create the program for all device. Use the first device as the
// representative device (assuming all device are of the same type).
std::string binary_file = getBoardBinaryFile("vectorAdd", device[0]);
printf("Using AOCX: %s\n", binary_file.c_str());
program = createProgramFromBinary(context, binary_file.c_str(), device, num_devices);
// Build the program that was just created.
status = clBuildProgram(program, 0, NULL, "", NULL, NULL);
checkError(status, "Failed to build program");
// Create per-device objects.
queue.reset(num_devices);
kernel.reset(num_devices);
n_per_device.reset(num_devices);
input_a_buf.reset(num_devices);
input_b_buf.reset(num_devices);
output_buf.reset(num_devices);
for(unsigned i = 0; i < num_devices; ++i) {
// Command queue.
queue[i] = clCreateCommandQueue(context, device[i], CL_QUEUE_PROFILING_ENABLE, &status);
checkError(status, "Failed to create command queue");
// Kernel.
const char *kernel_name = "vectorAdd";
kernel[i] = clCreateKernel(program, kernel_name, &status);
checkError(status, "Failed to create kernel");
// Determine the number of elements processed by this device.
n_per_device[i] = N / num_devices; // number of elements handled by this device
// Spread out the remainder of the elements over the first
// N % num_devices.
if(i < (N % num_devices)) {
n_per_device[i]++;
}
// Input buffers.
input_a_buf[i] = clCreateBuffer(context, CL_MEM_READ_ONLY,
n_per_device[i] * sizeof(float), NULL, &status);
checkError(status, "Failed to create buffer for input A");
input_b_buf[i] = clCreateBuffer(context, CL_MEM_READ_ONLY,
n_per_device[i] * sizeof(float), NULL, &status);
checkError(status, "Failed to create buffer for input B");
// Output buffer.
output_buf[i] = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
n_per_device[i] * sizeof(float), NULL, &status);
checkError(status, "Failed to create buffer for output");
}
return true;
}