Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Part1/PROJ_NIX/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NVCC = nvcc -m64
CC = gcc -m64
CPPC = g++ -m64

CUDA_FLAGS = -I/usr/local/cuda/samples/common/inc -I/usr/local/cuda/include
CUDA_FLAGS = -I/Developer/NVIDIA/CUDA-6.5/extras/CUPTI/include/GL -I/usr/local/cuda/samples/common/inc -I/usr/local/cuda/include

LFLAGS = -lglut -lGL -lGLEW

Expand All @@ -19,7 +19,7 @@ glslUtility.o: ../src/glslUtility.cpp
utilities.o: ../src/utilities.cpp
$(CPPC) $(CUDA_FLAGS) ../src/utilities.cpp -c

main.o: ../src/main.cpp ../src/glslUtility.h ../src/kernel.h ../src/utilities.h ../src/main.h
main.o: ../src/main.cpp ../src/glslUtility.h ../src/kernel.h ../src/utilities.h ../src/main.h /Developer/NVIDIA/CUDA-6.5/extras/CUPTI/include/GL/gl.h
$(CPPC) $(CUDA_FLAGS) ../src/main.cpp -c

565simulator: main.o kernel.o glslUtility.o utilities.o
Expand Down
12 changes: 6 additions & 6 deletions Part1/PROJ_WIN/CIS565_PROJ_1/CIS565_PROJ_1.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 5.5.props" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 6.5.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
Expand All @@ -46,12 +46,12 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(SolutionDir)/shared/glew/include/;$(SolutionDir)/shared/freeglut/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\Users\Robert Cassidy\Documents\Visual Studio 2010\Projects\Project-1\Part1\PROJ_WIN\shared\freeglut\include\GL;C:\Users\Robert Cassidy\Documents\Visual Studio 2010\Projects\Project-1\Part1\PROJ_WIN\shared\glew\include\GL;$(SolutionDir)/shared/glew/include/;$(SolutionDir)/shared/freeglut/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)/shared/glew/lib;$(SolutionDir)/shared/freeglut/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>C:\Users\Robert Cassidy\Documents\Visual Studio 2010\Projects\Project-1\Part1\PROJ_WIN\shared\freeglut\lib;C:\Users\Robert Cassidy\Documents\Visual Studio 2010\Projects\Project-1\Part1\PROJ_WIN\shared\glew\lib;$(SolutionDir)/shared/glew/lib;$(SolutionDir)/shared/freeglut/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opengl32.lib;glut32.lib;glew32.lib;freeglut.lib;cudart.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
Expand All @@ -62,7 +62,7 @@
<GPUDebugInfo>true</GPUDebugInfo>
<GenerateLineInfo>true</GenerateLineInfo>
<HostDebugInfo>true</HostDebugInfo>
<CodeGeneration>compute_10,sm_10;compute_20,sm_20;compute_30,sm_30</CodeGeneration>
<CodeGeneration>compute_20,sm_20;compute_30,sm_30</CodeGeneration>
</CudaCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down Expand Up @@ -95,7 +95,7 @@
<ItemGroup>
<CudaCompile Include="..\..\src\kernel.cu">
<FileType>Document</FileType>
<CodeGeneration Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">compute_10,sm_10;compute_20,sm_20</CodeGeneration>
<CodeGeneration Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">compute_20,sm_20</CodeGeneration>
</CudaCompile>
</ItemGroup>
<ItemGroup>
Expand All @@ -114,6 +114,6 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 5.5.targets" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 6.5.targets" />
</ImportGroup>
</Project>
739 changes: 370 additions & 369 deletions Part1/PROJ_WIN/src/kernel.cu.deps

Large diffs are not rendered by default.

61 changes: 55 additions & 6 deletions Part1/src/kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
dim3 threadsPerBlock(blockSize);

int numObjects;
const float planetMass = 3e8;
const __device__ float planetMass = 3e8;
const __device__ float starMass = 5e10;

const float scene_scale = 2e2; //size of the height map in simulation space
Expand Down Expand Up @@ -87,21 +87,64 @@ __global__ void generateCircularVelArray(int time, int N, glm::vec3 * arr, glm::
// HINT : You may want to write a helper function that will help you
// calculate the acceleration contribution of a single body.
// REMEMBER : F = (G * m_a * m_b) / (r_ab ^ 2)

__device__ glm::vec3 accelerate(int N, glm::vec4 my_pos, glm::vec4 * their_pos)
{
return glm::vec3(0.0f);
glm::vec3 results(0.0f);
glm::vec4 r(0.0f);
float distR;
float denom;
for(int i = 0; i < N ; i++){
r.x = their_pos[i].x - my_pos.x;
r.y = their_pos[i].y - my_pos.y;
r.z = their_pos[i].z - my_pos.z;
distR = r.x * r.x + r.y * r.y + r.z * r.z;
//denominator = 1 / (dist^2)^2/3
if(distR < .25){ //to avoid planets shooting off into oblivion when they get near each other.
continue;
}
denom = 1.0f / sqrt(distR * distR * distR);
results.x += G * planetMass * denom * r.x;
results.y += G * planetMass * denom * r.y;
results.z += G * planetMass * denom * r.z;
}
//Planet Mass too
r.x = 0 - my_pos.x;
r.y = 0 - my_pos.y;
r.z = 0 - my_pos.z;
distR = r.x * r.x + r.y * r.y + r.z * r.z;
//denominator = 1 / (dist^2 + EPSILON)^3/2
if(distR > .25){ //to avoid planets shooting off into oblivion when they get near each other.
denom = 1.0f / sqrt(distR * distR * distR);
results.x += G * starMass * denom * r.x;
results.y += G * starMass * denom * r.y;
results.z += G * starMass * denom * r.z;
}
return results;
}

// TODO : update the acceleration of each body
__global__ void updateF(int N, float dt, glm::vec4 * pos, glm::vec3 * vel, glm::vec3 * acc)
{
// FILL IN HERE
int index = threadIdx.x + (blockIdx.x * blockDim.x);
acc[index] = accelerate(N,pos[index],pos);
//acc[index] = glm::vec3(1.0f);
return;
}

// TODO : update velocity and position using a simple Euler integration scheme
__global__ void updateS(int N, float dt, glm::vec4 * pos, glm::vec3 * vel, glm::vec3 * acc)
{
// FILL IN HERE
int index = threadIdx.x + (blockIdx.x * blockDim.x);
vel[index].x = vel[index].x + dt * acc[index].x;
vel[index].y = vel[index].y + dt * acc[index].y;
vel[index].z = vel[index].z + dt * acc[index].z;

pos[index].x = pos[index].x + dt * vel[index].x;
pos[index].y = pos[index].y + dt * vel[index].y;
pos[index].z = pos[index].z + dt * vel[index].z;
return;

}

// Update the vertex buffer object
Expand Down Expand Up @@ -137,7 +180,8 @@ __global__ void sendToPBO(int N, glm::vec4 * pos, float4 * pbo, int width, int h
float c_scale_h = height / s_scale;

glm::vec3 color(0.05, 0.15, 0.3);
glm::vec3 acc = accelerate(N, glm::vec4((x-w2)/c_scale_w,(y-h2)/c_scale_h,0,1), pos);
//glm::vec3 acc = accelerate(N, glm::vec4((x-w2)/c_scale_w,(y-h2)/c_scale_h,0,1), pos);
glm::vec3 acc(1.0f); //Changed this to speed it up since not being used in homework

if(x<width && y<height)
{
Expand Down Expand Up @@ -179,7 +223,12 @@ void initCuda(int N)
// TODO : Using the functions you wrote above, write a function that calls the CUDA kernels to update a single sim step
void cudaNBodyUpdateWrapper(float dt)
{
// FILL IN HERE
int threads = 128;
int blocks = numObjects / threads + 1;
updateF<<<blocks, threads>>>(numObjects, dt, dev_pos, dev_vel, dev_acc);
updateS<<<blocks, threads>>>(numObjects, dt, dev_pos, dev_vel, dev_acc);

return;
}

void cudaUpdateVBO(float * vbodptr, int width, int height)
Expand Down
2 changes: 1 addition & 1 deletion Part1/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "main.h"

#define N_FOR_VIS 5000
#define N_FOR_VIS 6000
#define DT 0.2
#define VISUALIZE 1
//-------------------------------
Expand Down
20 changes: 20 additions & 0 deletions Part3/cusamatrixmath.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cusamatrixmath", "cusamatrixmath\cusamatrixmath.vcxproj", "{2A8A854C-1E6A-44C5-B4B6-E66CCCC6E99D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2A8A854C-1E6A-44C5-B4B6-E66CCCC6E99D}.Debug|Win32.ActiveCfg = Debug|Win32
{2A8A854C-1E6A-44C5-B4B6-E66CCCC6E99D}.Debug|Win32.Build.0 = Debug|Win32
{2A8A854C-1E6A-44C5-B4B6-E66CCCC6E99D}.Release|Win32.ActiveCfg = Release|Win32
{2A8A854C-1E6A-44C5-B4B6-E66CCCC6E99D}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
25 changes: 25 additions & 0 deletions Part3/cusamatrixmath/cudaMat4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// CIS565 CUDA Raytracer: A parallel raytracer for Patrick Cozzi's CIS565: GPU Computing at the University of Pennsylvania
// Written by Yining Karl Li, Copyright (c) 2012 University of Pennsylvania
// This file includes code from:
// Yining Karl Li's TAKUA Render, a massively parallel pathtracing renderer: http://www.yiningkarlli.com

#ifndef CUDAMAT4_H
#define CUDAMAT4_H

#include "glm/glm.hpp"
#include <cuda_runtime.h>

struct cudaMat3{
glm::vec3 x;
glm::vec3 y;
glm::vec3 z;
};

struct cudaMat4{
glm::vec4 x;
glm::vec4 y;
glm::vec4 z;
glm::vec4 w;
};

#endif
74 changes: 74 additions & 0 deletions Part3/cusamatrixmath/cusamatrixmath.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="matrix_math.cu" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="matrix_math.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{2A8A854C-1E6A-44C5-B4B6-E66CCCC6E99D}</ProjectGuid>
<RootNamespace>cusamatrixmath</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 6.5.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>cudart.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 6.5.targets" />
</ImportGroup>
</Project>
27 changes: 27 additions & 0 deletions Part3/cusamatrixmath/cusamatrixmath.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="matrix_math.cu">
<Filter>Source Files</Filter>
</CudaCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="matrix_math.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions Part3/cusamatrixmath/glslUtility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// GLSL Utility: A utility class for loading GLSL shaders, for Patrick Cozzi's CIS565: GPU Computing at the University of Pennsylvania
// Written by Varun Sampath and Patrick Cozzi, Copyright (c) 2012 University of Pennsylvania

#ifndef GLSLUTILITY_H_
#define GLSLUTILITY_H_

#ifdef __APPLE__
#include <GL/glfw.h>
#else
#include <GL/glew.h>
#endif

namespace glslUtility
{

GLuint createProgram(const char *vertexShaderPath, const char *fragmentShaderPath, const char *attributeLocations[], GLuint numberOfLocations);
GLuint createProgram(const char *vertexShaderPath, const char *geometryShaderPath, const char *fragmentShaderPath, const char *attributeLocations[], GLuint numberOfLocations);

}

#endif
18 changes: 18 additions & 0 deletions Part3/cusamatrixmath/kernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef KERNEL_H
#define KERNEL_H

#include <stdio.h>
#include <thrust/random.h>
#include <cuda.h>
#include <cmath>

#define blockSize 128
#define checkCUDAErrorWithLine(msg) checkCUDAError(msg, __LINE__)
#define SHARED 0

void checkCUDAError(const char *msg, int line);
void cudaNBodyUpdateWrapper(float dt);
void initCuda(int N);
void cudaUpdatePBO(float4 * pbodptr, int width, int height);
void cudaUpdateVBO(float * vbodptr, int width, int height);
#endif
Loading