Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit b8db7cd

Browse files
committed
Change example programs to use integers (randomly generated floats were
suffering stability correctness) Former-commit-id: 85e0ef3
1 parent fec2e20 commit b8db7cd

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

examples/device/example_device_reduce.cu

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/******************************************************************************
3030
* Simple example of DeviceReduce::Sum().
3131
*
32-
* Sums an array of float keys.
32+
* Sums an array of int keys.
3333
*
3434
* To compile using the command line:
3535
* nvcc -arch=sm_XX example_device_reduce.cu -I../.. -lcudart -O3
@@ -65,7 +65,7 @@ CachingDeviceAllocator g_allocator(true); // Caching allocator for device memo
6565
* Initialize problem
6666
*/
6767
void Initialize(
68-
float *h_in,
68+
int *h_in,
6969
int num_items)
7070
{
7171
for (int i = 0; i < num_items; ++i)
@@ -84,8 +84,8 @@ void Initialize(
8484
* Compute solution
8585
*/
8686
void Solve(
87-
float *h_in,
88-
float &h_reference,
87+
int *h_in,
88+
int &h_reference,
8989
int num_items)
9090
{
9191
for (int i = 0; i < num_items; ++i)
@@ -129,27 +129,27 @@ int main(int argc, char** argv)
129129
CubDebugExit(args.DeviceInit());
130130

131131
printf("cub::DeviceReduce::Sum() %d items (%d-byte elements)\n",
132-
num_items, (int) sizeof(float));
132+
num_items, (int) sizeof(int));
133133
fflush(stdout);
134134

135135
// Allocate host arrays
136-
float* h_in = new float[num_items];
137-
float h_reference;
136+
int* h_in = new int[num_items];
137+
int h_reference;
138138

139139
// Initialize problem and solution
140140
Initialize(h_in, num_items);
141141
Solve(h_in, h_reference, num_items);
142142

143143
// Allocate problem device arrays
144-
float *d_in = NULL;
145-
CubDebugExit(g_allocator.DeviceAllocate((void**)&d_in, sizeof(float) * num_items));
144+
int *d_in = NULL;
145+
CubDebugExit(g_allocator.DeviceAllocate((void**)&d_in, sizeof(int) * num_items));
146146

147147
// Initialize device input
148-
CubDebugExit(cudaMemcpy(d_in, h_in, sizeof(float) * num_items, cudaMemcpyHostToDevice));
148+
CubDebugExit(cudaMemcpy(d_in, h_in, sizeof(int) * num_items, cudaMemcpyHostToDevice));
149149

150150
// Allocate device output array
151-
float *d_out = NULL;
152-
CubDebugExit(g_allocator.DeviceAllocate((void**)&d_out, sizeof(float) * 1));
151+
int *d_out = NULL;
152+
CubDebugExit(g_allocator.DeviceAllocate((void**)&d_out, sizeof(int) * 1));
153153

154154
// Request and allocate temporary storage
155155
void *d_temp_storage = NULL;

examples/device/example_device_scan.cu

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/******************************************************************************
3030
* Simple example of DeviceScan::ExclusiveSum().
3131
*
32-
* Computes an exclusive sum of float keys.
32+
* Computes an exclusive sum of int keys.
3333
*
3434
* To compile using the command line:
3535
* nvcc -arch=sm_XX example_device_scan.cu -I../.. -lcudart -O3
@@ -66,7 +66,7 @@ CachingDeviceAllocator g_allocator(true); // Caching allocator for device memo
6666
* Initialize problem
6767
*/
6868
void Initialize(
69-
float *h_in,
69+
int *h_in,
7070
int num_items)
7171
{
7272
for (int i = 0; i < num_items; ++i)
@@ -83,13 +83,13 @@ void Initialize(
8383
/**
8484
* Solve exclusive-scan problem
8585
*/
86-
float Solve(
87-
float *h_in,
88-
float *h_reference,
86+
int Solve(
87+
int *h_in,
88+
int *h_reference,
8989
int num_items)
9090
{
91-
float inclusive = 0.0;
92-
float aggregate = 0.0;
91+
int inclusive = 0.0;
92+
int aggregate = 0.0;
9393

9494
for (int i = 0; i < num_items; ++i)
9595
{
@@ -134,27 +134,27 @@ int main(int argc, char** argv)
134134
CubDebugExit(args.DeviceInit());
135135

136136
printf("cub::DeviceScan::ExclusiveSum %d items (%d-byte elements)\n",
137-
num_items, (int) sizeof(float));
137+
num_items, (int) sizeof(int));
138138
fflush(stdout);
139139

140140
// Allocate host arrays
141-
float* h_in = new float[num_items];
142-
float* h_reference = new float[num_items];
141+
int* h_in = new int[num_items];
142+
int* h_reference = new int[num_items];
143143

144144
// Initialize problem and solution
145145
Initialize(h_in, num_items);
146146
Solve(h_in, h_reference, num_items);
147147

148148
// Allocate problem device arrays
149-
float *d_in = NULL;
150-
CubDebugExit(g_allocator.DeviceAllocate((void**)&d_in, sizeof(float) * num_items));
149+
int *d_in = NULL;
150+
CubDebugExit(g_allocator.DeviceAllocate((void**)&d_in, sizeof(int) * num_items));
151151

152152
// Initialize device input
153-
CubDebugExit(cudaMemcpy(d_in, h_in, sizeof(float) * num_items, cudaMemcpyHostToDevice));
153+
CubDebugExit(cudaMemcpy(d_in, h_in, sizeof(int) * num_items, cudaMemcpyHostToDevice));
154154

155155
// Allocate device output array
156-
float *d_out = NULL;
157-
CubDebugExit(g_allocator.DeviceAllocate((void**)&d_out, sizeof(float) * num_items));
156+
int *d_out = NULL;
157+
CubDebugExit(g_allocator.DeviceAllocate((void**)&d_out, sizeof(int) * num_items));
158158

159159
// Allocate temporary storage
160160
void *d_temp_storage = NULL;

0 commit comments

Comments
 (0)