mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-23 21:28:17 +08:00
add and update samples for CUDA 11.5
This commit is contained in:
49
Samples/VFlockingD3D10/README.md
Normal file
49
Samples/VFlockingD3D10/README.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# VFlockingD3D10 - VFlockingD3D10
|
||||
|
||||
## Description
|
||||
|
||||
The sample models formation of V-shaped flocks by big birds, such as geese and cranes. The algorithms of such flocking are borrowed from the paper "V-like formations in flocks of artificial birds" from Artificial Life, Vol. 14, No. 2, 2008. The sample has CPU- and GPU-based implementations. Press 'g' to toggle between them. The GPU-based simulation works many times faster than the CPU-based one. The printout in the console window reports the simulation time per step. Press 'r' to reset the initial distribution of birds.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
Graphics Interop, Data Parallel Algorithms, Physically-Based Simulation, Performance Strategies
|
||||
|
||||
## Supported SM Architectures
|
||||
|
||||
[SM 3.5 ](https://developer.nvidia.com/cuda-gpus) [SM 3.7 ](https://developer.nvidia.com/cuda-gpus) [SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 6.0 ](https://developer.nvidia.com/cuda-gpus) [SM 6.1 ](https://developer.nvidia.com/cuda-gpus) [SM 7.0 ](https://developer.nvidia.com/cuda-gpus) [SM 7.2 ](https://developer.nvidia.com/cuda-gpus) [SM 7.5 ](https://developer.nvidia.com/cuda-gpus) [SM 8.0 ](https://developer.nvidia.com/cuda-gpus) [SM 8.6 ](https://developer.nvidia.com/cuda-gpus)
|
||||
|
||||
## Supported OSes
|
||||
|
||||
Windows
|
||||
|
||||
## Supported CPU Architecture
|
||||
|
||||
x86_64
|
||||
|
||||
## CUDA APIs involved
|
||||
|
||||
### [CUDA Runtime API](http://docs.nvidia.com/cuda/cuda-runtime-api/index.html)
|
||||
cudaD3D10SetGLDevice, cudaGraphicsMapResources, cudaGraphicsUnmapResources, cudaGraphicsResourceGetMappedPointer, cudaGraphicsRegisterResource, cudaGraphicsGLRegisterBuffer, cudaGraphicsUnregisterResource
|
||||
|
||||
## Dependencies needed to build/run
|
||||
[DirectX](../../README.md#directx)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Download and install the [CUDA Toolkit 11.5](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
||||
|
||||
## Build and Run
|
||||
|
||||
### Windows
|
||||
The Windows samples are built using the Visual Studio IDE. Solution files (.sln) are provided for each supported version of Visual Studio, using the format:
|
||||
```
|
||||
*_vs<version>.sln - for Visual Studio <version>
|
||||
```
|
||||
Each individual sample has its own set of solution files in its directory:
|
||||
|
||||
To build/examine all the samples at once, the complete solution files should be used. To build/examine a single sample, the individual sample solution files should be used.
|
||||
> **Note:** Some samples require that the Microsoft DirectX SDK (June 2010 or newer) be installed and that the VC++ directory paths are properly set up (**Tools > Options...**). Check DirectX Dependencies section for details."
|
||||
|
||||
## References (for more details)
|
||||
|
||||
1260
Samples/VFlockingD3D10/VFlockingD3D10.cpp
Normal file
1260
Samples/VFlockingD3D10/VFlockingD3D10.cpp
Normal file
File diff suppressed because it is too large
Load Diff
45
Samples/VFlockingD3D10/VFlockingD3D10.h
Normal file
45
Samples/VFlockingD3D10/VFlockingD3D10.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef VFLOCKING_D3D10_H
|
||||
#define VFLOCKING_D3D10_H
|
||||
|
||||
#pragma once
|
||||
|
||||
// simulation parameters
|
||||
struct Params {
|
||||
float alpha;
|
||||
float upwashX;
|
||||
float upwashY;
|
||||
float wingspan;
|
||||
float dX;
|
||||
float dY;
|
||||
float epsilon;
|
||||
float lambda; // -0.1073f * wingspan ;
|
||||
};
|
||||
|
||||
#endif
|
||||
20
Samples/VFlockingD3D10/VFlockingD3D10_vs2017.sln
Normal file
20
Samples/VFlockingD3D10/VFlockingD3D10_vs2017.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2017
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VFlockingD3D10", "VFlockingD3D10_vs2017.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
116
Samples/VFlockingD3D10/VFlockingD3D10_vs2017.vcxproj
Normal file
116
Samples/VFlockingD3D10/VFlockingD3D10_vs2017.vcxproj
Normal file
@@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>VFlockingD3D10_vs2017</RootNamespace>
|
||||
<ProjectName>VFlockingD3D10</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(WindowsTargetPlatformVersion)'==''">
|
||||
<LatestTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</LatestTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition="'$(WindowsTargetPlatformVersion)' == ''">$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
|
||||
<TargetPlatformVersion>$(WindowsTargetPlatformVersion)</TargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.5.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../Common;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>cudart_static.lib;d3d10.lib;d3dcompiler.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/VFlockingD3D10.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
<AdditionalOptions>--threads 0</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="VFlockingD3D10.cpp" />
|
||||
<CudaCompile Include="VFlocking_kernel.cu" />
|
||||
<ClCompile Include="..\..\Common\rendercheck_d3d10.cpp" />
|
||||
<ClInclude Include="VFlockingD3D10.h" />
|
||||
<ClInclude Include="..\..\Common\rendercheck_d3d10.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.5.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
20
Samples/VFlockingD3D10/VFlockingD3D10_vs2019.sln
Normal file
20
Samples/VFlockingD3D10/VFlockingD3D10_vs2019.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2019
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VFlockingD3D10", "VFlockingD3D10_vs2019.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
112
Samples/VFlockingD3D10/VFlockingD3D10_vs2019.vcxproj
Normal file
112
Samples/VFlockingD3D10/VFlockingD3D10_vs2019.vcxproj
Normal file
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>VFlockingD3D10_vs2019</RootNamespace>
|
||||
<ProjectName>VFlockingD3D10</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.5.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../Common;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>cudart_static.lib;d3d10.lib;d3dcompiler.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/VFlockingD3D10.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
<AdditionalOptions>--threads 0</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="VFlockingD3D10.cpp" />
|
||||
<CudaCompile Include="VFlocking_kernel.cu" />
|
||||
<ClCompile Include="..\..\Common\rendercheck_d3d10.cpp" />
|
||||
<ClInclude Include="VFlockingD3D10.h" />
|
||||
<ClInclude Include="..\..\Common\rendercheck_d3d10.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.5.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
288
Samples/VFlockingD3D10/VFlocking_kernel.cu
Normal file
288
Samples/VFlockingD3D10/VFlocking_kernel.cu
Normal file
@@ -0,0 +1,288 @@
|
||||
/* Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <helper_cuda.h>
|
||||
#include <helper_math.h>
|
||||
#include <VFlockingD3D10.h>
|
||||
|
||||
#define PI 3.1415926536f
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
__device__ bool isInsideQuad_D(float2 pos0, float2 pos1, float width,
|
||||
float height) {
|
||||
if (fabs(pos0.x - pos1.x) < 0.5f * width &&
|
||||
fabs(pos0.y - pos1.y) < 0.5f * height) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__device__ bool isInsideBird(float2 pixel, float2 pos, float width,
|
||||
float height, float radius) {
|
||||
if (abs(pixel.x - pos.x) < 0.5f * width &&
|
||||
abs(pixel.y - pos.y) < 0.5f * height ||
|
||||
(pixel.x - pos.x) * (pixel.x - pos.x) +
|
||||
(pixel.y - pos.y) * (pixel.y - pos.y) <
|
||||
radius * radius) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void cuda_kernel_update(float2 *newPos, float2 *curPos,
|
||||
uint numBirds, bool *hasproxy,
|
||||
bool *neighbors, bool *rightgoals,
|
||||
bool *leftgoals, Params *params) {
|
||||
uint i = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
|
||||
if (i >= numBirds) {
|
||||
return;
|
||||
}
|
||||
|
||||
float minDist = 50000.f;
|
||||
float2 dij = make_float2(0.f);
|
||||
|
||||
if (!hasproxy[i]) {
|
||||
for (uint j = 0; j < numBirds; j++) {
|
||||
if (j == i) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (leftgoals[i * numBirds + j]) {
|
||||
dij = params->dX * normalize(curPos[j] - curPos[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bool collision = false;
|
||||
|
||||
for (uint j = 0; j < numBirds; j++) {
|
||||
float d;
|
||||
|
||||
if (leftgoals[i * numBirds + j]) {
|
||||
d = curPos[j].x - (params->wingspan + params->lambda) - curPos[i].x;
|
||||
|
||||
if (fabs(d) < fabs(minDist)) {
|
||||
minDist = d;
|
||||
}
|
||||
}
|
||||
|
||||
if (rightgoals[i * numBirds + j]) {
|
||||
d = curPos[j].x + (params->wingspan + params->lambda) - curPos[i].x;
|
||||
|
||||
if (fabs(d) < fabs(minDist)) {
|
||||
minDist = d;
|
||||
}
|
||||
}
|
||||
|
||||
if (neighbors[i * numBirds + j] && !collision) {
|
||||
if (curPos[j].y >= curPos[i].y &&
|
||||
curPos[j].y < curPos[i].y + params->epsilon) {
|
||||
dij.y = -params->dY;
|
||||
collision = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fabs(minDist) <= params->dX) {
|
||||
return;
|
||||
}
|
||||
|
||||
dij.x = minDist > 0 ? params->dX : -params->dX;
|
||||
}
|
||||
|
||||
newPos[i].x = curPos[i].x + dij.x;
|
||||
newPos[i].y = curPos[i].y + dij.y;
|
||||
}
|
||||
|
||||
__global__ void cuda_kernel_checktriples(float2 *pos, uint numBirds,
|
||||
bool *hasproxy, bool *neighbors,
|
||||
bool *rightgoals, bool *leftgoals,
|
||||
uint3 *triples, Params *params) {
|
||||
uint ith = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
|
||||
if (ith >= numBirds * (numBirds - 1) * (numBirds - 2) / 6) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint a[3];
|
||||
a[0] = triples[ith].x;
|
||||
a[1] = triples[ith].y;
|
||||
a[2] = triples[ith].z;
|
||||
|
||||
uint i, j, x;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 2; j > i; j--) {
|
||||
if (pos[a[j - 1]].y > pos[a[j]].y) {
|
||||
x = a[j - 1];
|
||||
a[j - 1] = a[j];
|
||||
a[j] = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasproxy[a[0]]) {
|
||||
float a2a1 = pos[a[2]].x - pos[a[1]].x;
|
||||
|
||||
if (fabs(a2a1) < 2.f * (params->wingspan + params->lambda))
|
||||
if (a2a1 >= 0) {
|
||||
if (leftgoals[a[0] * numBirds + a[2]]) {
|
||||
leftgoals[a[0] * numBirds + a[2]] = false;
|
||||
}
|
||||
|
||||
if (rightgoals[a[0] * numBirds + a[1]]) {
|
||||
rightgoals[a[0] * numBirds + a[1]] = false;
|
||||
}
|
||||
} else {
|
||||
if (leftgoals[a[0] * numBirds + a[1]]) {
|
||||
leftgoals[a[0] * numBirds + a[1]] = false;
|
||||
}
|
||||
|
||||
if (rightgoals[a[0] * numBirds + a[2]]) {
|
||||
rightgoals[a[0] * numBirds + a[2]] = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((leftgoals[a[0] * numBirds + a[2]]) &&
|
||||
(leftgoals[a[0] * numBirds + a[1]]))
|
||||
if ((length(pos[a[1]] - pos[a[0]]) < length(pos[a[2]] - pos[a[0]]))) {
|
||||
leftgoals[a[0] * numBirds + a[2]] = false;
|
||||
} else {
|
||||
leftgoals[a[0] * numBirds + a[1]] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void cuda_kernel_checkpairs(float2 *pos, uint numBirds,
|
||||
bool *hasproxy, bool *neighbors,
|
||||
bool *rightgoals, bool *leftgoals,
|
||||
uint2 *pairs, Params *params) {
|
||||
uint i = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
|
||||
if (i >= numBirds * (numBirds - 1) / 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint front, back;
|
||||
|
||||
if (pos[pairs[i].y].y > pos[pairs[i].x].y) {
|
||||
front = pairs[i].y;
|
||||
back = pairs[i].x;
|
||||
} else {
|
||||
front = pairs[i].x;
|
||||
back = pairs[i].y;
|
||||
}
|
||||
|
||||
leftgoals[back * numBirds + front] = true;
|
||||
rightgoals[back * numBirds + front] = true;
|
||||
|
||||
float2 stepback;
|
||||
stepback.x = pos[front].x;
|
||||
stepback.y = pos[front].y - 0.5f * params->upwashY;
|
||||
|
||||
if (isInsideQuad_D(
|
||||
pos[back], stepback,
|
||||
2.f * (params->wingspan + params->lambda + params->upwashX),
|
||||
params->upwashY)) {
|
||||
neighbors[back * numBirds + front] = true;
|
||||
|
||||
if (!hasproxy[back]) {
|
||||
hasproxy[back] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void cuda_simulate(float2 *newPos, float2 *curPos, uint numBirds,
|
||||
bool *d_hasproxy, bool *d_neighbors,
|
||||
bool *d_leftgoals, bool *d_rightgoals,
|
||||
uint2 *d_pairs, uint3 *d_triples,
|
||||
Params *d_params) {
|
||||
cudaError_t error = cudaSuccess;
|
||||
float tempms;
|
||||
static float ms = 0.f;
|
||||
static uint step = 0;
|
||||
int smallblockSize = 32, midblockSize = 128, bigblockSize = 32;
|
||||
|
||||
cudaEvent_t e_start, e_stop;
|
||||
cudaEventCreate(&e_start);
|
||||
cudaEventCreate(&e_stop);
|
||||
cudaEventRecord(e_start, 0);
|
||||
|
||||
cudaMemset(d_leftgoals, 0, numBirds * numBirds * sizeof(bool));
|
||||
cudaMemset(d_rightgoals, 0, numBirds * numBirds * sizeof(bool));
|
||||
cudaMemset(d_hasproxy, 0, numBirds * sizeof(bool));
|
||||
cudaMemset(d_neighbors, 0, numBirds * numBirds * sizeof(bool));
|
||||
|
||||
dim3 Db = dim3(bigblockSize);
|
||||
dim3 Dg =
|
||||
dim3((numBirds * (numBirds - 1) / 2 + bigblockSize - 1) / bigblockSize);
|
||||
cuda_kernel_checkpairs<<<Dg, Db>>>(curPos, numBirds, d_hasproxy, d_neighbors,
|
||||
d_rightgoals, d_leftgoals, d_pairs,
|
||||
d_params);
|
||||
|
||||
Db = dim3(midblockSize);
|
||||
Dg =
|
||||
dim3((numBirds * (numBirds - 1) * (numBirds - 2) / 6 + bigblockSize - 1) /
|
||||
bigblockSize);
|
||||
cuda_kernel_checktriples<<<Dg, Db>>>(curPos, numBirds, d_hasproxy,
|
||||
d_neighbors, d_rightgoals, d_leftgoals,
|
||||
d_triples, d_params);
|
||||
|
||||
Db = dim3(smallblockSize);
|
||||
Dg = dim3((numBirds + smallblockSize - 1) / smallblockSize);
|
||||
cuda_kernel_update<<<Dg, Db>>>(newPos, curPos, numBirds, d_hasproxy,
|
||||
d_neighbors, d_rightgoals, d_leftgoals,
|
||||
d_params /*, d_pWingTips */);
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
|
||||
cudaEventRecord(e_stop, 0);
|
||||
cudaEventSynchronize(e_stop);
|
||||
cudaEventElapsedTime(&tempms, e_start, e_stop);
|
||||
ms += tempms;
|
||||
|
||||
if (!(step % 100) && step) {
|
||||
printf("GPU, step %d \ntime per step %6.3f ms \n", step, ms / 100.f);
|
||||
ms = 0.f;
|
||||
}
|
||||
|
||||
step++;
|
||||
|
||||
error = cudaGetLastError();
|
||||
|
||||
if (error != cudaSuccess) {
|
||||
printf("one of the cuda kernels failed to launch, error = %d\n", error);
|
||||
}
|
||||
}
|
||||
5
Samples/VFlockingD3D10/data/ref_VFlockingD3D10.ppm
Normal file
5
Samples/VFlockingD3D10/data/ref_VFlockingD3D10.ppm
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user