#define CUB_STDERR
#include <stdio.h>
#include "../../test/test_util.h"
using namespace cub;
bool g_verbose = false;
void Initialize(
int *h_in,
int num_items)
{
for (int i = 0; i < num_items; ++i)
h_in[i] = i;
if (g_verbose)
{
printf("Input:\n");
DisplayResults(h_in, num_items);
printf("\n\n");
}
}
int Solve(
int *h_in,
int *h_reference,
int num_items)
{
int inclusive = 0;
int aggregate = 0;
for (int i = 0; i < num_items; ++i)
{
h_reference[i] = inclusive;
inclusive += h_in[i];
aggregate += h_in[i];
}
return aggregate;
}
int main(int argc, char** argv)
{
int num_items = 150;
CommandLineArgs args(argc, argv);
g_verbose = args.CheckCmdLineFlag("v");
args.GetCmdLineArgument("n", num_items);
if (args.CheckCmdLineFlag("help"))
{
printf("%s "
"[--n=<input items> "
"[--device=<device-id>] "
"[--v] "
"\n", argv[0]);
exit(0);
}
printf("cub::DeviceScan::ExclusiveSum %d items (%d-byte elements)\n",
num_items, (int) sizeof(int));
fflush(stdout);
int* h_in = new int[num_items];
int* h_reference = new int[num_items];
Initialize(h_in, num_items);
Solve(h_in, h_reference, num_items);
int *d_in = NULL;
CubDebugExit(g_allocator.DeviceAllocate((
void**)&d_in,
sizeof(
int) * num_items));
CubDebugExit(cudaMemcpy(d_in, h_in,
sizeof(
int) * num_items, cudaMemcpyHostToDevice));
int *d_out = NULL;
CubDebugExit(g_allocator.DeviceAllocate((
void**)&d_out,
sizeof(
int) * num_items));
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
CubDebugExit(g_allocator.DeviceAllocate(&d_temp_storage, temp_storage_bytes));
int compare = CompareDeviceResults(h_reference, d_out, num_items, true, g_verbose);
printf("\t%s", compare ? "FAIL" : "PASS");
AssertEquals(0, compare);
if (h_in) delete[] h_in;
if (h_reference) delete[] h_reference;
if (d_temp_storage)
CubDebugExit(g_allocator.DeviceFree(d_temp_storage));
printf("\n\n");
return 0;
}