Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 1: Henry Zhu #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

Maknee
Copy link

@Maknee Maknee commented Sep 9, 2018

Features

  • Has naive, uniform, and coherent implementations of boid simulation
  • Has an awesome repo cover that includes answers to questions mentioned in INSTRUCTIONS, FPS performance graph and Nsight performance summaries for these different implementations (with different number of boids and blocks)
  • checkCUDAErrorWithLine("error") gets reduced to checkCUDAError(), which tells the file, line and tracks the error.
  • Uses c++11 features (type traits, variadic templates, lamdas...):
/*type_traits*/
//swap pointers (helps with ping pong)
template<typename T, typename std::enable_if<std::is_pointer<T>::value>::type* = nullptr>
void swap_pointers(T& p1, T& p2)
{
  T temp = p1;
  p1 = p2;
  p2 = temp;
}
/*variadic templates*/
template<typename Type = int, typename... Ts>
__device__ auto truncate_to(Ts*... ts)
{
  (void)std::initializer_list<int>{(*ts = static_cast<Type>(*ts), 0)...};
}
  • Uses plenty templating and lambdas to abstract details.
  • For example (abstracts checking rules):
template<typename CheckSuccessCallback>
__device__ void check_rule(float rule_distance, int this_boid, int other_boid, const glm::vec3* pos, CheckSuccessCallback check_success_callback)
{
  const auto& this_boid_pos = pos[this_boid];
  const auto& other_boid_pos = pos[other_boid];

  if (this_boid != other_boid && glm::distance(this_boid_pos, other_boid_pos) < rule_distance)
  {
    check_success_callback();
  }
}
  • Rule 1 uses above by specifying the arguments more
__device__ void check_rule1(int this_boid, int other_boid, const glm::vec3* pos, glm::vec3& perceived_center, int& num_neighbors)
{
  check_rule(rule1Distance, this_boid, other_boid, pos,
             [&]()
             {
               const auto& other_boid_pos = pos[other_boid];
               perceived_center += other_boid_pos;
               num_neighbors++;
             });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant