Skip to content

Commit 77dfb0d

Browse files
committed
clang-format stuff without sorting includes
1 parent 75c7a67 commit 77dfb0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1615
-1688
lines changed

LectureQuizzes/1_30.cu

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
#include <stdio.h>
22

3-
__global__ void cube(float * d_out, float * d_in){
4-
// Todo: Fill in this function
3+
__global__ void cube(float *d_out, float *d_in) {
4+
// Todo: Fill in this function
55
}
66

7-
int main(int argc, char ** argv) {
8-
const int ARRAY_SIZE = 64;
9-
const int ARRAY_BYTES = ARRAY_SIZE * sizeof(float);
7+
int main(int argc, char **argv) {
8+
const int ARRAY_SIZE = 64;
9+
const int ARRAY_BYTES = ARRAY_SIZE * sizeof(float);
1010

11-
// generate the input array on the host
12-
float h_in[ARRAY_SIZE];
13-
for (int i = 0; i < ARRAY_SIZE; i++) {
14-
h_in[i] = float(i);
15-
}
16-
float h_out[ARRAY_SIZE];
11+
// generate the input array on the host
12+
float h_in[ARRAY_SIZE];
13+
for (int i = 0; i < ARRAY_SIZE; i++) {
14+
h_in[i] = float(i);
15+
}
16+
float h_out[ARRAY_SIZE];
1717

18-
// declare GPU memory pointers
19-
float * d_in;
20-
float * d_out;
18+
// declare GPU memory pointers
19+
float *d_in;
20+
float *d_out;
2121

22-
// allocate GPU memory
23-
cudaMalloc((void**) &d_in, ARRAY_BYTES);
24-
cudaMalloc((void**) &d_out, ARRAY_BYTES);
22+
// allocate GPU memory
23+
cudaMalloc((void **)&d_in, ARRAY_BYTES);
24+
cudaMalloc((void **)&d_out, ARRAY_BYTES);
2525

26-
// transfer the array to the GPU
27-
cudaMemcpy(d_in, h_in, ARRAY_BYTES, cudaMemcpyHostToDevice);
26+
// transfer the array to the GPU
27+
cudaMemcpy(d_in, h_in, ARRAY_BYTES, cudaMemcpyHostToDevice);
2828

29-
// launch the kernel
30-
cube<<<1, ARRAY_SIZE>>>(d_out, d_in);
29+
// launch the kernel
30+
cube<<<1, ARRAY_SIZE>>>(d_out, d_in);
3131

32-
// copy back the result array to the CPU
33-
cudaMemcpy(h_out, d_out, ARRAY_BYTES, cudaMemcpyDeviceToHost);
32+
// copy back the result array to the CPU
33+
cudaMemcpy(h_out, d_out, ARRAY_BYTES, cudaMemcpyDeviceToHost);
3434

35-
// print out the resulting array
36-
for (int i =0; i < ARRAY_SIZE; i++) {
37-
printf("%f", h_out[i]);
38-
printf(((i % 4) != 3) ? "\t" : "\n");
39-
}
35+
// print out the resulting array
36+
for (int i = 0; i < ARRAY_SIZE; i++) {
37+
printf("%f", h_out[i]);
38+
printf(((i % 4) != 3) ? "\t" : "\n");
39+
}
4040

41-
cudaFree(d_in);
42-
cudaFree(d_out);
41+
cudaFree(d_in);
42+
cudaFree(d_out);
4343

44-
return 0;
44+
return 0;
4545
}

assignments/HW1/HW1.cpp

100755100644
+27-24
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
cv::Mat imageRGBA;
1010
cv::Mat imageGrey;
1111

12-
uchar4 *d_rgbaImage__;
12+
uchar4 *d_rgbaImage__;
1313
unsigned char *d_greyImage__;
1414

1515
size_t numRows() { return imageRGBA.rows; }
1616
size_t numCols() { return imageRGBA.cols; }
1717

18-
//return types are void since any internal error will be handled by quitting
19-
//no point in returning error codes...
20-
//returns a pointer to an RGBA version of the input image
21-
//and a pointer to the single channel grey-scale output
22-
//on both the host and device
18+
// return types are void since any internal error will be handled by quitting
19+
// no point in returning error codes...
20+
// returns a pointer to an RGBA version of the input image
21+
// and a pointer to the single channel grey-scale output
22+
// on both the host and device
2323
void preProcess(uchar4 **inputImage, unsigned char **greyImage,
2424
uchar4 **d_rgbaImage, unsigned char **d_greyImage,
2525
const std::string &filename) {
26-
//make sure the context initializes ok
26+
// make sure the context initializes ok
2727
checkCudaErrors(cudaFree(0));
2828

2929
cv::Mat image;
@@ -35,50 +35,53 @@ void preProcess(uchar4 **inputImage, unsigned char **greyImage,
3535

3636
cv::cvtColor(image, imageRGBA, CV_BGR2RGBA);
3737

38-
//allocate memory for the output
38+
// allocate memory for the output
3939
imageGrey.create(image.rows, image.cols, CV_8UC1);
4040

41-
//This shouldn't ever happen given the way the images are created
42-
//at least based upon my limited understanding of OpenCV, but better to check
41+
// This shouldn't ever happen given the way the images are created
42+
// at least based upon my limited understanding of OpenCV, but better to check
4343
if (!imageRGBA.isContinuous() || !imageGrey.isContinuous()) {
4444
std::cerr << "Images aren't continuous!! Exiting." << std::endl;
4545
exit(1);
4646
}
4747

4848
*inputImage = (uchar4 *)imageRGBA.ptr<unsigned char>(0);
49-
*greyImage = imageGrey.ptr<unsigned char>(0);
49+
*greyImage = imageGrey.ptr<unsigned char>(0);
5050

5151
const size_t numPixels = numRows() * numCols();
52-
//allocate memory on the device for both input and output
52+
// allocate memory on the device for both input and output
5353
checkCudaErrors(cudaMalloc(d_rgbaImage, sizeof(uchar4) * numPixels));
5454
checkCudaErrors(cudaMalloc(d_greyImage, sizeof(unsigned char) * numPixels));
55-
checkCudaErrors(cudaMemset(*d_greyImage, 0, numPixels * sizeof(unsigned char))); //make sure no memory is left laying around
55+
checkCudaErrors(cudaMemset(
56+
*d_greyImage, 0,
57+
numPixels *
58+
sizeof(unsigned char))); // make sure no memory is left laying around
5659

57-
//copy input array to the GPU
58-
checkCudaErrors(cudaMemcpy(*d_rgbaImage, *inputImage, sizeof(uchar4) * numPixels, cudaMemcpyHostToDevice));
60+
// copy input array to the GPU
61+
checkCudaErrors(cudaMemcpy(*d_rgbaImage, *inputImage,
62+
sizeof(uchar4) * numPixels,
63+
cudaMemcpyHostToDevice));
5964

6065
d_rgbaImage__ = *d_rgbaImage;
6166
d_greyImage__ = *d_greyImage;
6267
}
6368

64-
void postProcess(const std::string& output_file, unsigned char* data_ptr) {
65-
cv::Mat output(numRows(), numCols(), CV_8UC1, (void*)data_ptr);
69+
void postProcess(const std::string &output_file, unsigned char *data_ptr) {
70+
cv::Mat output(numRows(), numCols(), CV_8UC1, (void *)data_ptr);
6671

67-
//output the image
72+
// output the image
6873
cv::imwrite(output_file.c_str(), output);
6974
}
7075

71-
void cleanup()
72-
{
73-
//cleanup
76+
void cleanup() {
77+
// cleanup
7478
cudaFree(d_rgbaImage__);
7579
cudaFree(d_greyImage__);
7680
}
7781

78-
void generateReferenceImage(std::string input_filename, std::string output_filename)
79-
{
82+
void generateReferenceImage(std::string input_filename,
83+
std::string output_filename) {
8084
cv::Mat reference = cv::imread(input_filename, CV_LOAD_IMAGE_GRAYSCALE);
8185

8286
cv::imwrite(output_filename, reference);
83-
8487
}

assignments/HW1/compare.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,39 @@
44

55
#include "utils.h"
66

7-
void compareImages(std::string reference_filename, std::string test_filename,
8-
bool useEpsCheck, double perPixelError, double globalError)
9-
{
7+
void compareImages(std::string reference_filename, std::string test_filename,
8+
bool useEpsCheck, double perPixelError, double globalError) {
109
cv::Mat reference = cv::imread(reference_filename, -1);
1110
cv::Mat test = cv::imread(test_filename, -1);
1211

1312
cv::Mat diff = abs(reference - test);
1413

15-
cv::Mat diffSingleChannel = diff.reshape(1, 0); //convert to 1 channel, same # rows
14+
cv::Mat diffSingleChannel =
15+
diff.reshape(1, 0); // convert to 1 channel, same # rows
1616

1717
double minVal, maxVal;
1818

19-
cv::minMaxLoc(diffSingleChannel, &minVal, &maxVal, NULL, NULL); //NULL because we don't care about location
19+
cv::minMaxLoc(diffSingleChannel, &minVal, &maxVal, NULL,
20+
NULL); // NULL because we don't care about location
2021

21-
//now perform transform so that we bump values to the full range
22+
// now perform transform so that we bump values to the full range
2223

2324
diffSingleChannel = (diffSingleChannel - minVal) * (255. / (maxVal - minVal));
2425

2526
diff = diffSingleChannel.reshape(reference.channels(), 0);
2627

2728
cv::imwrite("HW1_differenceImage.png", diff);
28-
//OK, now we can start comparing values...
29+
// OK, now we can start comparing values...
2930
unsigned char *referencePtr = reference.ptr<unsigned char>(0);
3031
unsigned char *testPtr = test.ptr<unsigned char>(0);
3132

3233
if (useEpsCheck) {
33-
checkResultsEps(referencePtr, testPtr, reference.rows * reference.cols * reference.channels(), perPixelError, globalError);
34-
}
35-
else
36-
{
37-
checkResultsExact(referencePtr, testPtr, reference.rows * reference.cols * reference.channels());
34+
checkResultsEps(referencePtr, testPtr,
35+
reference.rows * reference.cols * reference.channels(),
36+
perPixelError, globalError);
37+
} else {
38+
checkResultsExact(referencePtr, testPtr,
39+
reference.rows * reference.cols * reference.channels());
3840
}
3941

4042
std::cout << "PASS" << std::endl;

assignments/HW1/compare.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef COMPARE_H__
22
#define COMPARE_H__
33

4-
void compareImages(std::string reference_filename, std::string test_filename,
4+
void compareImages(std::string reference_filename, std::string test_filename,
55
bool useEpsCheck, double perPixelError, double globalError);
66

77
#endif

assignments/HW1/main.cpp

100755100644
+55-48
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//Udacity HW1 Solution
1+
// Udacity HW1 Solution
22

33
#include <iostream>
44
#include "timer.h"
@@ -8,83 +8,90 @@
88
#include "reference_calc.h"
99
#include "compare.h"
1010

11-
void your_rgba_to_greyscale(const uchar4 * const h_rgbaImage,
12-
uchar4 * const d_rgbaImage,
13-
unsigned char* const d_greyImage,
14-
size_t numRows, size_t numCols);
11+
void your_rgba_to_greyscale(const uchar4 *const h_rgbaImage,
12+
uchar4 *const d_rgbaImage,
13+
unsigned char *const d_greyImage, size_t numRows,
14+
size_t numCols);
1515

16-
//include the definitions of the above functions for this homework
16+
// include the definitions of the above functions for this homework
1717
#include "HW1.cpp"
1818

1919
int main(int argc, char **argv) {
20-
uchar4 *h_rgbaImage, *d_rgbaImage;
20+
uchar4 *h_rgbaImage, *d_rgbaImage;
2121
unsigned char *h_greyImage, *d_greyImage;
2222

2323
std::string input_file;
2424
std::string output_file;
2525
std::string reference_file;
2626
double perPixelError = 0.0;
27-
double globalError = 0.0;
27+
double globalError = 0.0;
2828
bool useEpsCheck = false;
29-
switch (argc)
30-
{
31-
case 2:
32-
input_file = std::string(argv[1]);
33-
output_file = "HW1_output.png";
34-
reference_file = "HW1_reference.png";
35-
break;
36-
case 3:
37-
input_file = std::string(argv[1]);
38-
output_file = std::string(argv[2]);
39-
reference_file = "HW1_reference.png";
40-
break;
41-
case 4:
42-
input_file = std::string(argv[1]);
43-
output_file = std::string(argv[2]);
44-
reference_file = std::string(argv[3]);
45-
break;
46-
case 6:
47-
useEpsCheck=true;
48-
input_file = std::string(argv[1]);
49-
output_file = std::string(argv[2]);
50-
reference_file = std::string(argv[3]);
51-
perPixelError = atof(argv[4]);
52-
globalError = atof(argv[5]);
53-
break;
54-
default:
55-
std::cerr << "Usage: ./HW1 input_file [output_filename] [reference_filename] [perPixelError] [globalError]" << std::endl;
56-
exit(1);
29+
switch (argc) {
30+
case 2:
31+
input_file = std::string(argv[1]);
32+
output_file = "HW1_output.png";
33+
reference_file = "HW1_reference.png";
34+
break;
35+
case 3:
36+
input_file = std::string(argv[1]);
37+
output_file = std::string(argv[2]);
38+
reference_file = "HW1_reference.png";
39+
break;
40+
case 4:
41+
input_file = std::string(argv[1]);
42+
output_file = std::string(argv[2]);
43+
reference_file = std::string(argv[3]);
44+
break;
45+
case 6:
46+
useEpsCheck = true;
47+
input_file = std::string(argv[1]);
48+
output_file = std::string(argv[2]);
49+
reference_file = std::string(argv[3]);
50+
perPixelError = atof(argv[4]);
51+
globalError = atof(argv[5]);
52+
break;
53+
default:
54+
std::cerr << "Usage: ./HW1 input_file [output_filename] "
55+
"[reference_filename] [perPixelError] [globalError]"
56+
<< std::endl;
57+
exit(1);
5758
}
58-
//load the image and give us our input and output pointers
59-
preProcess(&h_rgbaImage, &h_greyImage, &d_rgbaImage, &d_greyImage, input_file);
59+
// load the image and give us our input and output pointers
60+
preProcess(&h_rgbaImage, &h_greyImage, &d_rgbaImage, &d_greyImage,
61+
input_file);
6062

6163
GpuTimer timer;
6264
timer.Start();
63-
//call the students' code
64-
your_rgba_to_greyscale(h_rgbaImage, d_rgbaImage, d_greyImage, numRows(), numCols());
65+
// call the students' code
66+
your_rgba_to_greyscale(h_rgbaImage, d_rgbaImage, d_greyImage, numRows(),
67+
numCols());
6568
timer.Stop();
66-
cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError());
69+
cudaDeviceSynchronize();
70+
checkCudaErrors(cudaGetLastError());
6771

6872
int err = printf("Your code ran in: %f msecs.\n", timer.Elapsed());
6973

7074
if (err < 0) {
71-
//Couldn't print! Probably the student closed stdout - bad news
72-
std::cerr << "Couldn't print timing information! STDOUT Closed!" << std::endl;
75+
// Couldn't print! Probably the student closed stdout - bad news
76+
std::cerr << "Couldn't print timing information! STDOUT Closed!"
77+
<< std::endl;
7378
exit(1);
7479
}
7580

76-
size_t numPixels = numRows()*numCols();
77-
checkCudaErrors(cudaMemcpy(h_greyImage, d_greyImage, sizeof(unsigned char) * numPixels, cudaMemcpyDeviceToHost));
81+
size_t numPixels = numRows() * numCols();
82+
checkCudaErrors(cudaMemcpy(h_greyImage, d_greyImage,
83+
sizeof(unsigned char) * numPixels,
84+
cudaMemcpyDeviceToHost));
7885

79-
//check results and output the grey image
86+
// check results and output the grey image
8087
postProcess(output_file, h_greyImage);
8188

8289
referenceCalculation(h_rgbaImage, h_greyImage, numRows(), numCols());
8390

8491
postProcess(reference_file, h_greyImage);
8592

86-
//generateReferenceImage(input_file, reference_file);
87-
compareImages(reference_file, output_file, useEpsCheck, perPixelError,
93+
// generateReferenceImage(input_file, reference_file);
94+
compareImages(reference_file, output_file, useEpsCheck, perPixelError,
8895
globalError);
8996

9097
cleanup();

0 commit comments

Comments
 (0)