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_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.0.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 Down Expand Up @@ -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.0.targets" />
</ImportGroup>
</Project>
739 changes: 370 additions & 369 deletions Part1/PROJ_WIN/src/kernel.cu.deps

Large diffs are not rendered by default.

83 changes: 74 additions & 9 deletions Part1/src/kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,61 @@ __global__ void generateCircularVelArray(int time, int N, glm::vec3 * arr, glm::
}
}

// TODO: Core force calc kernel global memory
// Core force calc kernel global memory
// 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);
// Get the index for this body
int index = threadIdx.x + (blockIdx.x * blockDim.x);

// Initialize the output vector
glm::vec3 F = glm::vec3(0.0f, 0.0f, 0.0f);

// Loop through and add contributions from each other body
for (size_t i = 0; i < N; i++) {
// Skip the current body since it doesn't apply a force to itself
if (i == index) {
continue;
}

glm::vec4 diff = their_pos[i] - my_pos;
glm::vec3 r = glm::vec3(diff);
float mag = G * their_pos[i].w / (glm::length(r) * glm::length(r));
F += mag * r / glm::length(r);
}

// Add the contribution from the star
glm::vec3 r = glm::vec3(my_pos);
float mag = G * starMass / (glm::length(r) * glm::length(r));
F -= mag * r / glm::length(r);

return F;
}

// TODO : update the acceleration of each body
__global__ void updateF(int N, float dt, glm::vec4 * pos, glm::vec3 * vel, glm::vec3 * acc)
// update the acceleration of each body
__global__ void updateF(int N, glm::vec4 * pos, glm::vec3 * acc)
{
// FILL IN HERE
// Get the index for this body
int index = threadIdx.x + (blockIdx.x * blockDim.x);

// Calculate the acceleration on the body
acc[index] = accelerate(N, pos[index], pos);
}

// TODO : update velocity and position using a simple Euler integration scheme
// 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
// Get the index for this body
int index = threadIdx.x + (blockIdx.x * blockDim.x);

// Update the velocity through euler integration
vel[index] += dt * acc[index];

// Update the position
glm::vec4 v(vel[index], 0.0);
pos[index] += dt * v;
}

// Update the vertex buffer object
Expand Down Expand Up @@ -176,10 +212,39 @@ void initCuda(int N)
cudaThreadSynchronize();
}

// TODO : Using the functions you wrote above, write a function that calls the CUDA kernels to update a single sim step
// Call the CUDA kernels updateF and updateS to update a single sim step
void cudaNBodyUpdateWrapper(float dt)
{
// FILL IN HERE
dim3 fullBlocksPerGrid((int)ceil(float(numObjects)/float(blockSize)));

// Add events for profiling
cudaEvent_t beginEvent;
cudaEvent_t endEvent;
cudaEventCreate( &beginEvent );
cudaEventCreate( &endEvent );

// Compute accelerations from current positions
cudaEventRecord(beginEvent, 0);
updateF<<<fullBlocksPerGrid, blockSize>>>(numObjects, dev_pos, dev_acc);
cudaEventRecord(endEvent, 0);
cudaEventSynchronize(endEvent);
float timeValue;
cudaEventElapsedTime(&timeValue, beginEvent, endEvent);
fprintf(stdout, "updateF kernel time: %f.\n", timeValue);

// Wait for all accelerations to be updated
cudaThreadSynchronize();

// Update all positions and velocities from integrating the new acceleration
cudaEventRecord(beginEvent, 0);
updateS<<<fullBlocksPerGrid, blockSize>>>(numObjects, dt, dev_pos, dev_vel, dev_acc);
cudaEventRecord(endEvent, 0);
cudaEventSynchronize(endEvent);
cudaEventElapsedTime(&timeValue, beginEvent, endEvent);
fprintf(stdout, "updateS kernel time: %f.\n", timeValue);

// Wait for all positions to be updated
cudaThreadSynchronize();
}

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 1000
#define DT 0.2
#define VISUALIZE 1
//-------------------------------
Expand Down
20 changes: 20 additions & 0 deletions Part2/Part2.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}") = "Part2", "Part2\Part2.vcxproj", "{21083425-7EE2-4DEA-AAAD-4F8266BD2B06}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{21083425-7EE2-4DEA-AAAD-4F8266BD2B06}.Debug|Win32.ActiveCfg = Debug|Win32
{21083425-7EE2-4DEA-AAAD-4F8266BD2B06}.Debug|Win32.Build.0 = Debug|Win32
{21083425-7EE2-4DEA-AAAD-4F8266BD2B06}.Release|Win32.ActiveCfg = Release|Win32
{21083425-7EE2-4DEA-AAAD-4F8266BD2B06}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
75 changes: 75 additions & 0 deletions Part2/Part2/Part2.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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>
<PropertyGroup Label="Globals">
<ProjectGuid>{21083425-7EE2-4DEA-AAAD-4F8266BD2B06}</ProjectGuid>
<RootNamespace>Part2</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.0.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>
<AdditionalDependencies>cudart.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<CudaLink>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</CudaLink>
</ItemDefinitionGroup>
<ItemGroup>
<CudaCompile Include="matrix_math.cu" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 6.0.targets" />
</ImportGroup>
</Project>
22 changes: 22 additions & 0 deletions Part2/Part2/Part2.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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>
</Project>
Loading