Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Commit to make the branch compile #31

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
26 changes: 13 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@ if(CUDA_FOUND)
# to make sure more people can easily run class code without knowing
# about this compiler argument
set(CUDA_NVCC_FLAGS "
-ccbin /usr/bin/clang;
-ccbin /usr/bin/gcc;
-gencode;arch=compute_30,code=sm_30;
-gencode;arch=compute_35,code=sm_35;
-gencode;arch=compute_35,code=compute_35;
-gencode;arch=compute_20,code=sm_20;
-gencode;arch=compute_11,code=sm_11;
-gencode;arch=compute_12,code=sm_12;
-gencode;arch=compute_13,code=sm_13;")
-gencode;arch=compute_35,code=compute_35;")
#-gencode;arch=compute_20,code=sm_20;
#-gencode;arch=compute_11,code=sm_11;
#-gencode;arch=compute_12,code=sm_12;
#-gencode;arch=compute_13,code=sm_13;")

# add -Wextra compiler flag for gcc compilations
if (UNIX)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler -Wextra")
set(CMAKE_CXX_FLAGS "-stdlib=libstdc++")
#set(CMAKE_CXX_FLAGS "-stdlib=libstdc++")
endif (UNIX)

# add debugging to CUDA NVCC flags. For NVidia's NSight tools.
set(CUDA_NVCC_FLAGS_DEBUG ${CUDA_NVCC_FLAGS_DEBUG} "-G")

add_subdirectory (HW1)
add_subdirectory (HW2)
add_subdirectory (HW3)
add_subdirectory (HW4)
add_subdirectory (HW5)
add_subdirectory (HW6)
add_subdirectory ("Problem Sets/Problem Set 1")
add_subdirectory ("Problem Sets/Problem Set 2")
add_subdirectory ("Problem Sets/Problem Set 3")
add_subdirectory ("Problem Sets/Problem Set 4")
add_subdirectory ("Problem Sets/Problem Set 5")
add_subdirectory ("Problem Sets/Problem Set 6")
else(CUDA_FOUND)
message("CUDA is not installed on this system.")
endif()
256 changes: 221 additions & 35 deletions Problem Sets/Problem Set 1/Makefile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,54 +1,240 @@
NVCC=nvcc
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.5

###################################
# These are the default install #
# locations on most linux distros #
###################################
# Default target executed when no arguments are given to make.
default_target: all

OPENCV_LIBPATH=/usr/lib
OPENCV_INCLUDEPATH=/usr/include
.PHONY : default_target

###################################################
# On Macs the default install locations are below #
###################################################
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:

#OPENCV_LIBPATH=/usr/local/lib
#OPENCV_INCLUDEPATH=/usr/local/include

# or if using MacPorts
#=============================================================================
# Special targets provided by cmake.

#OPENCV_LIBPATH=/opt/local/lib
#OPENCV_INCLUDEPATH=/opt/local/include
# Disable implicit rules so canonical targets will work.
.SUFFIXES:

OPENCV_LIBS=-lopencv_core -lopencv_imgproc -lopencv_highgui

CUDA_INCLUDEPATH=/usr/local/cuda-5.0/include
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

######################################################
# On Macs the default install locations are below #
# ####################################################
.SUFFIXES: .hpux_make_needs_suffix_list

#CUDA_INCLUDEPATH=/usr/local/cuda/include
#CUDA_LIBPATH=/usr/local/cuda/lib

NVCC_OPTS=-O3 -arch=sm_20 -Xcompiler -Wall -Xcompiler -Wextra -m64
# Suppress display of executed commands.
$(VERBOSE).SILENT:

GCC_OPTS=-O3 -Wall -Wextra -m64

student: main.o student_func.o compare.o reference_calc.o Makefile
$(NVCC) -o HW1 main.o student_func.o compare.o reference_calc.o -L $(OPENCV_LIBPATH) $(OPENCV_LIBS) $(NVCC_OPTS)
# A target that is always out of date.
cmake_force:

main.o: main.cpp timer.h utils.h reference_calc.cpp compare.cpp HW1.cpp
g++ -c main.cpp $(GCC_OPTS) -I $(CUDA_INCLUDEPATH) -I $(OPENCV_INCLUDEPATH)
.PHONY : cmake_force

student_func.o: student_func.cu utils.h
nvcc -c student_func.cu $(NVCC_OPTS)
#=============================================================================
# Set environment variables for the build.

compare.o: compare.cpp compare.h
g++ -c compare.cpp -I $(OPENCV_INCLUDEPATH) $(GCC_OPTS) -I $(CUDA_INCLUDEPATH)
# The shell in which to execute make rules.
SHELL = /bin/sh

reference_calc.o: reference_calc.cpp reference_calc.h
g++ -c reference_calc.cpp -I $(OPENCV_INCLUDEPATH) $(GCC_OPTS) -I $(CUDA_INCLUDEPATH)
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/wuqiongs/cs344

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/wuqiongs/cs344

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
/usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache

.PHONY : edit_cache/fast

# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache

.PHONY : rebuild_cache/fast

# The main all target
all: cmake_check_build_system
cd /home/wuqiongs/cs344 && $(CMAKE_COMMAND) -E cmake_progress_start /home/wuqiongs/cs344/CMakeFiles "/home/wuqiongs/cs344/Problem Sets/Problem Set 1/CMakeFiles/progress.marks"
cd /home/wuqiongs/cs344 && $(MAKE) -f CMakeFiles/Makefile2 "Problem Sets/Problem Set 1/all"
$(CMAKE_COMMAND) -E cmake_progress_start /home/wuqiongs/cs344/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
rm -f *.o *.png hw
cd /home/wuqiongs/cs344 && $(MAKE) -f CMakeFiles/Makefile2 "Problem Sets/Problem Set 1/clean"
.PHONY : clean

# The main clean target
clean/fast: clean

.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
cd /home/wuqiongs/cs344 && $(MAKE) -f CMakeFiles/Makefile2 "Problem Sets/Problem Set 1/preinstall"
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
cd /home/wuqiongs/cs344 && $(MAKE) -f CMakeFiles/Makefile2 "Problem Sets/Problem Set 1/preinstall"
.PHONY : preinstall/fast

# clear depends
depend:
cd /home/wuqiongs/cs344 && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

# Convenience name for target.
Problem\ Sets/Problem\ Set\ 1/CMakeFiles/HW1.dir/rule:
cd /home/wuqiongs/cs344 && $(MAKE) -f CMakeFiles/Makefile2 "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/rule"
.PHONY : Problem\ Sets/Problem\ Set\ 1/CMakeFiles/HW1.dir/rule

# Convenience name for target.
HW1: Problem\ Sets/Problem\ Set\ 1/CMakeFiles/HW1.dir/rule

.PHONY : HW1

# fast build rule for target.
HW1/fast:
cd /home/wuqiongs/cs344 && $(MAKE) -f "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build.make" "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build"
.PHONY : HW1/fast

compare.o: compare.cpp.o

.PHONY : compare.o

# target to build an object file
compare.cpp.o:
cd /home/wuqiongs/cs344 && $(MAKE) -f "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build.make" "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/compare.cpp.o"
.PHONY : compare.cpp.o

compare.i: compare.cpp.i

.PHONY : compare.i

# target to preprocess a source file
compare.cpp.i:
cd /home/wuqiongs/cs344 && $(MAKE) -f "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build.make" "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/compare.cpp.i"
.PHONY : compare.cpp.i

compare.s: compare.cpp.s

.PHONY : compare.s

# target to generate assembly for a file
compare.cpp.s:
cd /home/wuqiongs/cs344 && $(MAKE) -f "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build.make" "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/compare.cpp.s"
.PHONY : compare.cpp.s

main.o: main.cpp.o

.PHONY : main.o

# target to build an object file
main.cpp.o:
cd /home/wuqiongs/cs344 && $(MAKE) -f "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build.make" "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/main.cpp.o"
.PHONY : main.cpp.o

main.i: main.cpp.i

.PHONY : main.i

# target to preprocess a source file
main.cpp.i:
cd /home/wuqiongs/cs344 && $(MAKE) -f "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build.make" "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/main.cpp.i"
.PHONY : main.cpp.i

main.s: main.cpp.s

.PHONY : main.s

# target to generate assembly for a file
main.cpp.s:
cd /home/wuqiongs/cs344 && $(MAKE) -f "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build.make" "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/main.cpp.s"
.PHONY : main.cpp.s

reference_calc.o: reference_calc.cpp.o

.PHONY : reference_calc.o

# target to build an object file
reference_calc.cpp.o:
cd /home/wuqiongs/cs344 && $(MAKE) -f "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build.make" "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/reference_calc.cpp.o"
.PHONY : reference_calc.cpp.o

reference_calc.i: reference_calc.cpp.i

.PHONY : reference_calc.i

# target to preprocess a source file
reference_calc.cpp.i:
cd /home/wuqiongs/cs344 && $(MAKE) -f "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build.make" "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/reference_calc.cpp.i"
.PHONY : reference_calc.cpp.i

reference_calc.s: reference_calc.cpp.s

.PHONY : reference_calc.s

# target to generate assembly for a file
reference_calc.cpp.s:
cd /home/wuqiongs/cs344 && $(MAKE) -f "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/build.make" "Problem Sets/Problem Set 1/CMakeFiles/HW1.dir/reference_calc.cpp.s"
.PHONY : reference_calc.cpp.s

# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... HW1"
@echo "... rebuild_cache"
@echo "... compare.o"
@echo "... compare.i"
@echo "... compare.s"
@echo "... main.o"
@echo "... main.i"
@echo "... main.s"
@echo "... reference_calc.o"
@echo "... reference_calc.i"
@echo "... reference_calc.s"
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
cd /home/wuqiongs/cs344 && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

28 changes: 25 additions & 3 deletions Problem Sets/Problem Set 1/student_func.cu
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@

#include "utils.h"

// This is used for Quadro P4000.
// In total, a 2D block has 32 * 32 = 1024 threads,
// the maximum on a P4000.
// Somehow 16 x 16 block size performs better than
// 32 x 32 block size.
int BLOCK_DIM = 16;

__global__
void rgba_to_greyscale(const uchar4* const rgbaImage,
unsigned char* const greyImage,
int numRows, int numCols)
{
//TODO
//Fill in the kernel to convert from color to greyscale
//the mapping from components of a uchar4 to RGBA is:
// .x -> R ; .y -> G ; .z -> B ; .w -> A
Expand All @@ -50,15 +56,31 @@ void rgba_to_greyscale(const uchar4* const rgbaImage,
//First create a mapping from the 2D block and grid locations
//to an absolute 2D location in the image, then use that to
//calculate a 1D offset
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;

if (x < numCols && y < numRows) {
int offset = y * numCols + x;
uchar4 rgba = rgbaImage[offset];

float channelSum = 0.299f * rgba.x + 0.587f * rgba.y + 0.114f * rgba.z;
greyImage[offset] = channelSum;
}
}

void your_rgba_to_greyscale(const uchar4 * const h_rgbaImage, uchar4 * const d_rgbaImage,
unsigned char* const d_greyImage, size_t numRows, size_t numCols)
{
//You must fill in the correct sizes for the blockSize and gridSize
//currently only one block with one thread is being launched
const dim3 blockSize(1, 1, 1); //TODO
const dim3 gridSize( 1, 1, 1); //TODO
const dim3 blockSize(BLOCK_DIM, BLOCK_DIM, 1);

//Compute the sizes of the grid
int gridRow = (numRows + BLOCK_DIM - 1) / BLOCK_DIM;
int gridCol = (numCols + BLOCK_DIM - 1) / BLOCK_DIM;

// Crucial! Col is for x index, Row is for y index!
const dim3 gridSize(gridCol, gridRow, 1);
rgba_to_greyscale<<<gridSize, blockSize>>>(d_rgbaImage, d_greyImage, numRows, numCols);

cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError());
Expand Down
Loading