Skip to content

Commit

Permalink
GenDataMP6 is giving better numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
acgreek committed Jan 29, 2013
1 parent 44f699a commit d90a0ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ add_custom_command(OUTPUT vecA.txt vecB.txt vecC.txt COMMAND GenDataMP1 90 DEPE
add_custom_command(OUTPUT matA.txt matB.txt matC.txt COMMAND GenDataMP2 90 10 39 DEPENDS GenDataMP2)
add_custom_command(OUTPUT vecSumA.txt vecSumResult.txt vecSumResult.txt COMMAND GenDataMP4 1000 DEPENDS GenDataMP4)
add_custom_command(OUTPUT vecCumSumA.txt vecCumSumResult.txt vecCumSumResult.txt COMMAND GenDataMP5 100 DEPENDS GenDataMP5)
add_custom_command(OUTPUT imageInput.txt convolutionMatrix.txt imageOutput.txt COMMAND GenDataMP6 10 10 3 5 5 DEPENDS GenDataMP6)
add_custom_command(OUTPUT imageInput.txt convolutionMatrix.txt imageOutput.txt COMMAND GenDataMP6 10 10 3 5 5 bl DEPENDS GenDataMP6)

add_custom_target(run1 mp1 vecA.txt vecB.txt vecC.txt DEPENDS vecA.txt vecB.txt vecC.txt )
add_custom_target(run2 mp2 matA.txt matB.txt matC.txt DEPENDS matA.txt matB.txt matC.txt)
Expand Down
43 changes: 33 additions & 10 deletions GenDataMP6.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

typedef std::vector< float > FloatVec;

bool g_generateSmallInt=false;

float genRandomFloat()
{
if ( g_generateSmallInt)
return rand() %10;
return ( (float) rand() / RAND_MAX );
}

Expand All @@ -32,21 +36,30 @@ void genMatrix( FloatVec&mat, int rows, int cols )

float sumAt( FloatVec& in,FloatVec& mask, int xC, int yC, int cC, int xMax, int yMax, int cMax) {
float sum=0;
for (int x = max(xC -2, 0); x < min(xMax,xC+2); x++) {
for (int y =max(yC -2,0); y < min(yMax,yC+2); y++) {
int index = (y*xMax +x)*cMax + cC;
sum+= in[index]*mask[y*5+x];
int mY=0;
for (int y =yC-2; y < min(yMax,yC+3); y++) {
int mX=0;
for (int x = xC-2; x < min(xMax,xC+3); x++) {
if (y >=0 && x >=0) {
int index = (y*xMax +x)*cMax + cC;
// std::cout << "at x=" << x << " y=" << y << " c=" << cC << " adding " << sum << " to " << in[index]*mask[mY*5+mX] << " in[index]=" << in[index]<< " mask[mY*5+mX] =" <<mask[mY*5+mX] << " mY=" << mY << " mX=" << mX ;
sum+= in[index]*mask[mY*5+mX];
// std::cout << "result sum " << sum << std::endl;
}
mX++;
}
mY++;
}

// std::cout << "done with sum: " << sum << std::endl;
return sum;
}
#define UNUSED __attribute__((unused))
void sumVector( FloatVec& in,FloatVec &out,FloatVec &mask, UNUSED const int mXLen,UNUSED const int mYLen, const int xLen,const int yLen, const int cLen)
{
out.clear();
for ( int x = 0; x < (int) xLen; ++x ) {
for ( int y = 0; y < (int) yLen; ++y) {
for ( int y = 0; y < (int) yLen; ++y) {
for ( int x = 0; x < (int) xLen; ++x ) {
for ( int c = 0; c < (int) cLen; ++c) {
out.push_back(sumAt(in,mask, x,y,c, xLen, yLen, cLen));
}
Expand All @@ -71,8 +84,14 @@ void writeVector( const FloatVec& vec, const int xLen,const int yLen, const int
outFile << yLen << std::endl;
outFile << cLen << std::endl;

for ( int i = 0; i < (xLen*yLen*cLen); ++i ) {
outFile << vec[i] << std::endl;
for ( int y = 0; y < (yLen); ++y ) {
for ( int x = 0; x < (xLen); ++x ) {
for ( int c = 0; c < (cLen); ++c ) {
int index = (y*xLen +x)*cLen + c;
outFile << vec[index] << " ";
}
}
outFile << std::endl;
}
}
void writeMatrix(const FloatVec& mat, int rows, int cols, const char* fname )
Expand Down Expand Up @@ -108,15 +127,19 @@ int main( int argc, const char** argv )
// Info for user

std::cout <<argv[0] << ": Generates data files to use as input for assignment MP.\n";
std::cout << "Invoke as: " << argv[0] << " [X] [Y] [Channels] [MaskX] [MaskY]\n\n";
std::cout << "Invoke as: " << argv[0] << " [X] [Y] [Channels] [MaskX] [MaskY] (" << argc << ")\n\n";

// Read input

if ( 6 != argc )
if ( 6 > argc )
{
std::cout << "Error! Wrong number of arguments to program.\n";
return 0;
}
if (7 == argc)
g_generateSmallInt=true;



// Create vectors

Expand Down

0 comments on commit d90a0ef

Please sign in to comment.