Difference between revisions of "GPU610/OctoPig"

From CDOT Wiki
Jump to: navigation, search
(Chad's Profiling Findings)
(Chad's Profiling Findings)
Line 25: Line 25:
 
After profiling I determined that 99% of the run was being spent in two functions, 89% and 10% respectively. The code for the two functions is below.
 
After profiling I determined that 99% of the run was being spent in two functions, 89% and 10% respectively. The code for the two functions is below.
  
 +
<source lang="cpp">
 +
void Program::update(int numItrs) {
 +
for (int i = 0; i < numItrs; ++i)
 +
{
 +
int sy = map[mapWidth * yPos + xPos];
 +
int st = state;
  
 +
int idx = (numStates * sy + st) * 3;
 +
st = table[idx + 0];
 +
sy = table[idx + 1];
 +
int ac = table[idx + 2];
 +
 +
// Update the current state
 +
state = st;
 +
 +
// Write the new symbol
 +
map[mapWidth * yPos + xPos] = sy;
 +
 +
// Perform the transition action
 +
switch (ac)
 +
{
 +
case ACTION_LEFT:
 +
xPos += 1;
 +
if (xPos >= mapWidth)
 +
xPos -= mapWidth;
 +
break;
 +
 +
case ACTION_RIGHT:
 +
xPos -= 1;
 +
if (xPos < 0)
 +
xPos += mapWidth;
 +
break;
 +
 +
case ACTION_UP:
 +
yPos -= 1;
 +
if (yPos < 0)
 +
yPos += mapHeight;
 +
break;
 +
 +
case ACTION_DOWN:
 +
yPos += 1;
 +
if (yPos >= mapHeight)
 +
yPos -= mapHeight;
 +
break;
 +
 +
default:
 +
error("invalid action: " + ac);
 +
}
 +
 +
itrCount++;
 +
}
 +
}
 +
</source>
  
  

Revision as of 23:32, 20 February 2013


GPU610/DPS915 | Student List | Group and Project Index | Student Resources | Glossary

TBA

Team Members

  1. Chad Pilkey
  2. Justin Robinson

Email All

Progress

Assignment 1

We began by profiling two things: a string-comparison algorithm, and a program which develops quasi-random visuals from an initial seed using a Turing Machine algorithm.


Justin's Findings

String comparison was not a good choice. If anything, it makes more sense to do string comparison in a serial fashion than in parallel. Comparing two strings of over 13,000 characters each in such a fashion as to force the algorithm to compare them all just barely results in a runtime of 0.001 seconds.


Chad's Profiling Findings

I started with this blog post I found and the demo that Maxime Chevalier-Boisvert (the original creator) posted as a github page here. Make sure to press random a few times to see the different results. She also posted the source code here, the only issue was that it's all written in JavaScript. My main task for completely the assignment was to somehow port the code into C++. The biggest challenge while porting was migrating from a loosely typed language to a strongly typed one, but I managed in the end to successfully port and compile the code. I'm sure there's a lot of cleaning up I can do with my C++ code, but this first assignment was more just a proof of concept than anything else.

I decided to scrap the randomization part of the original program for now because I want to have consistent profile results every run. I chose to focus on the seed found here because who doesn't love the Matrix. I also decided to only generate 1000 images each time the program is run.

After profiling I determined that 99% of the run was being spent in two functions, 89% and 10% respectively. The code for the two functions is below.

void Program::update(int numItrs) {
	for (int i = 0; i < numItrs; ++i)
	{
		int sy = map[mapWidth * yPos + xPos];
		int st = state;

		int idx = (numStates * sy + st) * 3;
		st = table[idx + 0];
		sy = table[idx + 1];
		int ac = table[idx + 2];

		// Update the current state
		state = st;

		// Write the new symbol
		map[mapWidth * yPos + xPos] = sy;

		// Perform the transition action
		switch (ac)
		{
			case ACTION_LEFT:
			xPos += 1;
			if (xPos >= mapWidth)
				xPos -= mapWidth;
			break;

			case ACTION_RIGHT:
			xPos -= 1;
			if (xPos < 0)
				xPos += mapWidth;
			break;

			case ACTION_UP:
			yPos -= 1;
			if (yPos < 0)
				yPos += mapHeight;
			break;

			case ACTION_DOWN:
			yPos += 1;
			if (yPos >= mapHeight)
				yPos -= mapHeight;
			break;

			default:
			error("invalid action: " + ac);
		}

		itrCount++;
	}
}


Analysis: Of our two selections, the choice to move forward with the pattern generator is clear.

Difficulties Met:

One apparent difficulty is the need to port the pattern-generator from Javascript into C in order to make use of CUDA.


Summary:

  • String comparison is not an efficient use of parallel programming practises.


Resources:

Assignment 2

Assignment 3