Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a kernel function to the existing program using CUDA C so that a histogram of the data loaded in loadData() is created. The name

Add a kernel function to the existing program using CUDA C so that a histogram of the data loaded in loadData() is created. The name of the .bin file holding the data is set by a command line argument. The number of intervals in the histogram your kernel will create should also be a command line argument. All intervals need to be the same length. The left endpoint of the first interval needs to be the minimum value in the data and the right endpoint of the last interval needs to be the maximum value. The size of the data needs to be large enough so that not all of the data will fit into 1 block. Hint: loadData() will need some modifications, and you might want to incorporate a reduction algorithm into your kernel for the histogram.

The histogram should be displayed in the following format:

- :

- :

- :

histogram.cu

#include "cuda_runtime.h" #include "device_launch_parameters.h"

#include #include #include

//insert kernel here

void initData(float **vec_h, unsigned size, char* name) { FILE *fw = fopen(name, "wb"); *vec_h = (float*)malloc(size * sizeof(float));

if (*vec_h == NULL) { printf("Unable to allocate host "); }

for (unsigned int i = 0; i < size; i++) { (*vec_h)[i] = (rand() % 100) / 100.00; fprintf(fw, "%0.2f ", (*vec_h)[i]); } fclose(fw); }

void loadData(unsigned size, char* name) { FILE *fw; double vec_k[500];

fw = fopen(name, "rb");

for (unsigned i = 0; i < size; i++) { fscanf(fw, "%lf", &vec_k[i]); printf("%0.2f ", vec_k[i]); }

fclose(fw); }

int main(int argc, char* argv[]) { float *in_h; unsigned in_elements = 500;

char filename[50]; strcpy(filename, argv[1]); char tmp_name[50] = ".bin"; strcat(filename, tmp_name);

initData(&in_h, in_elements, filename); loadData(in_elements, filename); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions