Ejemplo n.º 1
0
static void handleViewResized(void *self, WMNotification * notification)
{
	WMSplitView *sPtr = (WMSplitView *) self;

#if 0
	printf("---- (handleViewResized - 1) ----\n");
	dumpSubviews(sPtr);
#endif

	updateConstraints(sPtr);
	checkSizes(sPtr);

	if (sPtr->constrainProc || sPtr->flags.subviewsWereManuallyMoved) {
		distributeOffsetFormEnd(sPtr, _GetSplitViewSize() - getTotalSize(sPtr));
		checkPositions(sPtr);
		updateSubviewsGeom(sPtr);
	} else
		adjustSplitViewSubviews(sPtr);

	assert(checkSizes(sPtr) == 0);

#if 0
	printf("---- (handleViewResized - 2) ----\n");
	dumpSubviews(sPtr);
#endif
}
Ejemplo n.º 2
0
void WMAdjustSplitViewSubviews(WMSplitView * sPtr)
{
	CHECK_CLASS(sPtr, WC_SplitView);

	checkSizes(sPtr);

	adjustSplitViewSubviews(sPtr);

	assert(checkSizes(sPtr) == 0);
}
Ejemplo n.º 3
0
static l_mem singlestep (lua_State *L) {
  global_State *g = G(L);
  switch (g->gcstate) {
    case GCSpause: {
      if (!isgenerational(g))
        markroot(g);  /* start a new collection */
      /* in any case, root must be marked */
      lua_assert(!iswhite(obj2gco(g->mainthread))
              && !iswhite(gcvalue(&g->l_registry)));
      g->gcstate = GCSpropagate;
      return GCROOTCOST;
    }
    case GCSpropagate: {
      if (g->gray)
        return propagatemark(g);
      else {  /* no more `gray' objects */
        g->gcstate = GCSatomic;  /* finish mark phase */
        atomic(L);
        return GCATOMICCOST;
      }
    }
    case GCSsweepstring: {
      if (g->sweepstrgc < g->strt.size) {
        sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
        return GCSWEEPCOST;
      }
      else {  /* no more strings to sweep */
        g->sweepgc = &g->finobj;  /* prepare to sweep finalizable objects */
        g->gcstate = GCSsweepudata;
        return 0;
      }
    }
    case GCSsweepudata: {
      if (*g->sweepgc) {
        g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
        return GCSWEEPMAX*GCSWEEPCOST;
      }
      else {
        g->sweepgc = &g->allgc;  /* go to next phase */
        g->gcstate = GCSsweep;
        return GCSWEEPCOST;
      }
    }
    case GCSsweep: {
      if (*g->sweepgc) {
        g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
        return GCSWEEPMAX*GCSWEEPCOST;
      }
      else {
        /* sweep main thread */
        GCObject *mt = obj2gco(g->mainthread);
        sweeplist(L, &mt, 1);
        checkSizes(L);
        g->gcstate = GCSpause;  /* finish collection */
        return GCSWEEPCOST;
      }
    }
    default: lua_assert(0); return 0;
  }
}
Ejemplo n.º 4
0
static void adjustSplitViewSubviews(WMSplitView * sPtr)
{
	W_SplitViewSubview *p;
	int i, count, adjSize, adjPad;

	CHECK_CLASS(sPtr, WC_SplitView);

#if 0
	printf("---- (adjustSplitViewSubviews - 1) ----\n");
	dumpSubviews(sPtr);
#endif

	if ((count = _GetSubviewsCount()) < 1)
		return;

	adjSize = (_GetSplitViewSize() - ((count - 1) * DIVIDER_THICKNESS)) / count;
	adjPad = (_GetSplitViewSize() - ((count - 1) * DIVIDER_THICKNESS)) % count;
	for (i = 0; i < count; i++) {
		p = _GetPSubviewStructAt(i);
		p->size = adjSize;
	}

	distributeOffsetEqually(sPtr, adjPad - checkSizes(sPtr));

	checkPositions(sPtr);
	updateSubviewsGeom(sPtr);

	sPtr->flags.subviewsWereManuallyMoved = 0;

#if 0
	printf("---- (adjustSplitViewSubviews - 2) ----\n");
	dumpSubviews(sPtr);
#endif
}
Ejemplo n.º 5
0
static lu_mem singlestep (lua_State *L) {
    global_State *g = G(L);
    switch (g->gcstate) {
    case GCSpause: {
        g->GCmemtrav = g->strt.size * sizeof(GCObject*);
        restartcollection(g);
        g->gcstate = GCSpropagate;
        return g->GCmemtrav;
    }
    case GCSpropagate: {
        g->GCmemtrav = 0;
        lua_assert(g->gray);
        propagatemark(g);
        if (g->gray == NULL)  /* no more gray objects? */
            g->gcstate = GCSatomic;  /* finish propagate phase */
        return g->GCmemtrav;  /* memory traversed in this step */
    }
    case GCSatomic: {
        lu_mem work;
        int sw;
        propagateall(g);  /* make sure gray list is empty */
        work = atomic(L);  /* work is what was traversed by 'atomic' */
        sw = entersweep(L);
        g->GCestimate = gettotalbytes(g);  /* first estimate */;
        return work + sw * GCSWEEPCOST;
    }
    case GCSswpallgc: {  /* sweep "regular" objects */
        return sweepstep(L, g, GCSswpfinobj, &g->finobj);
    }
    case GCSswpfinobj: {  /* sweep objects with finalizers */
        return sweepstep(L, g, GCSswptobefnz, &g->tobefnz);
    }
    case GCSswptobefnz: {  /* sweep objects to be finalized */
        return sweepstep(L, g, GCSswpend, NULL);
    }
    case GCSswpend: {  /* finish sweeps */
        makewhite(g, g->mainthread);  /* sweep main thread */
        checkSizes(L, g);
        g->gcstate = GCScallfin;
        return 0;
    }
    case GCScallfin: {  /* call remaining finalizers */
        if (g->tobefnz && g->gckind != KGC_EMERGENCY) {
            int n = runafewfinalizers(L);
            return (n * GCFINALIZECOST);
        }
        else {  /* emergency mode or no more finalizers */
            g->gcstate = GCSpause;  /* finish collection */
            return 0;
        }
    }
    default:
        lua_assert(0);
        return 0;
    }
}
Ejemplo n.º 6
0
static l_mem singlestep(lua_State *L) {
    global_State *g = G(L);
    /*lua_checkmemory(L);*/
    switch (g->gcstate) {
    case GCSpause: {
        markroot(L); /* start a new collection */
        return 0;
    }
    case GCSpropagate: {
        if (g->gray)
            return propagatemark(g);
        else { /* no more `gray' objects */
            atomic(L); /* finish mark phase */
            return 0;
        }
    }
    case GCSsweepstring: {
        lu_mem old = g->totalbytes;
        sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
        if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */
            g->gcstate = GCSsweep; /* end sweep-string phase */
        lua_assert(old >= g->totalbytes);
        g->estimate -= old - g->totalbytes;
        return GCSWEEPCOST;
    }
    case GCSsweep: {
        lu_mem old = g->totalbytes;
        g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
        if (*g->sweepgc == NULL) { /* nothing more to sweep? */
            checkSizes(L);
            g->gcstate = GCSfinalize; /* end sweep phase */
        }
        lua_assert(old >= g->totalbytes);
        g->estimate -= old - g->totalbytes;
        return GCSWEEPMAX * GCSWEEPCOST;
    }
    case GCSfinalize: {
        if (g->tmudata) {
            GCTM(L);
            if (g->estimate > GCFINALIZECOST)
                g->estimate -= GCFINALIZECOST;
            return GCFINALIZECOST;
        } else {
            g->gcstate = GCSpause; /* end collection */
            g->gcdept = 0;
            return 0;
        }
    }
    default:
        lua_assert(0);
        return 0;
    }
}
Ejemplo n.º 7
0
// lua的gc状态机,执行顺序和下面的状态的从大到小开始一致
static l_mem singlestep (lua_State *L) {
  global_State *g = G(L);
  /*lua_checkmemory(L);*/
  switch (g->gcstate) {
    case GCSpause: {// 初始状态
      markroot(L);  /* start a new collection */// 主要就是标记主线程对象(也就是从白色染成灰色)
      return 0;
    }
    case GCSpropagate: {// 这个状态也是一个标记过程,并且会被进入多次,也就是分布迭代
      if (g->gray)// 如果gray对象一直存在的话,反复调用propagatemark函数,等所有的gray对象都被标记了,就会进入atomic函数处理
        return propagatemark(g);
      else {  /* no more `gray' objects */
        atomic(L);  /* finish mark phase */// 原子操作
        return 0;
      }
    }
    case GCSsweepstring: {// 清理字符串的阶段
      lu_mem old = g->totalbytes;
      sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
      if (g->sweepstrgc >= g->strt.size)  /* nothing more to sweep? */
        g->gcstate = GCSsweep;  /* end sweep-string phase */
      lua_assert(old >= g->totalbytes);
      g->estimate -= old - g->totalbytes;
      return GCSWEEPCOST;
    }
    case GCSsweep: {
      lu_mem old = g->totalbytes;
      g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
      if (*g->sweepgc == NULL) {  /* nothing more to sweep? */
        checkSizes(L);
        g->gcstate = GCSfinalize;  /* end sweep phase */
      }
      lua_assert(old >= g->totalbytes);
      g->estimate -= old - g->totalbytes;
      return GCSWEEPMAX*GCSWEEPCOST;
    }
    case GCSfinalize: {
      if (g->tmudata) {
        GCTM(L);
        if (g->estimate > GCFINALIZECOST)
          g->estimate -= GCFINALIZECOST;
        return GCFINALIZECOST;
      }
      else {
        g->gcstate = GCSpause;  /* end collection */
        g->gcdept = 0;
        return 0;
      }
    }
    default: lua_assert(0); return 0;
  }
}
Ejemplo n.º 8
0
/** Merges the contents of other into this.
 *
 * Scan intervals in both other and this must be set. Intervals must be
 * identical or non-overlapping. If they are identical all other parameters (for
 * that index) must match.
 *
 * Time indices in `this` are preserved. Time indices added from `other` are
 * incremented by the scan count of that detector in `this`. The relative order
 * of time indices added from `other` is preserved. If the interval for a time
 * index in `other` is identical to a corresponding interval in `this`, it is
 * ignored, i.e., no time index is added.
 *
 * The `merge()` operation is private in `DetectorInfo`, and only
 * accessible through `ComponentInfo` (via a `friend` declaration)
 * because we need to avoid merging `DetectorInfo` without merging
 * `ComponentInfo`, since that would effectively let us create a non-sync
 * scan. Otherwise we cannot provide scanning-related methods in
 * `ComponentInfo` without component index.
 *
 * The `scanIntervals` are stored in `ComponentInfo` only, to make sure all
 * components have the same ones. The `bool` vector `merge` dictating whether
 * a given interval should be merged or not was built by `ComponentInfo` and
 * passed on to this function.
 */
void DetectorInfo::merge(const DetectorInfo &other,
                         const std::vector<bool> &merge) {
  checkSizes(other);
  for (size_t timeIndex = 0; timeIndex < other.scanCount(); ++timeIndex) {
    if (!merge[timeIndex])
      continue;
    auto &isMasked = m_isMasked.access();
    auto &positions = m_positions.access();
    auto &rotations = m_rotations.access();
    const size_t indexStart = other.linearIndex({0, timeIndex});
    size_t indexEnd = indexStart + size();
    isMasked.insert(isMasked.end(), other.m_isMasked->begin() + indexStart,
                    other.m_isMasked->begin() + indexEnd);
    positions.insert(positions.end(), other.m_positions->begin() + indexStart,
                     other.m_positions->begin() + indexEnd);
    rotations.insert(rotations.end(), other.m_rotations->begin() + indexStart,
                     other.m_rotations->begin() + indexEnd);
  }
}
Ejemplo n.º 9
0
Archivo: lgc.c Proyecto: gitrider/wxsj2
void luaC_collectgarbage (lua_State *L) {
  size_t deadmem = mark(L);
  luaC_sweep(L, 0);
  checkSizes(L, deadmem);
  luaC_callGCTM(L);
}
Ejemplo n.º 10
0
int main( int argc, char* argv[] )
{
  int N = -1;         // number of rows 2^12
  int M = -1;         // number of columns 2^10
  int S = -1;         // total size 2^22
  int nrepeat = 100;  // number of repeats of the test

  // Read command line arguments.
  for ( int i = 0; i < argc; i++ ) {
    if ( ( strcmp( argv[ i ], "-N" ) == 0 ) || ( strcmp( argv[ i ], "-Rows" ) == 0 ) ) {
      N = pow( 2, atoi( argv[ ++i ] ) );
      printf( "  User N is %d\n", N );
    }
    else if ( ( strcmp( argv[ i ], "-M" ) == 0 ) || ( strcmp( argv[ i ], "-Columns" ) == 0 ) ) {
      M = pow( 2, atof( argv[ ++i ] ) );
      printf( "  User M is %d\n", M );
    }
    else if ( ( strcmp( argv[ i ], "-S" ) == 0 ) || ( strcmp( argv[ i ], "-Size" ) == 0 ) ) {
      S = pow( 2, atof( argv[ ++i ] ) );
      printf( "  User S is %d\n", S );
    }
    else if ( strcmp( argv[ i ], "-nrepeat" ) == 0 ) {
      nrepeat = atoi( argv[ ++i ] );
    }
    else if ( ( strcmp( argv[ i ], "-h" ) == 0 ) || ( strcmp( argv[ i ], "-help" ) == 0 ) ) {
      printf( "  y^T*A*x Options:\n" );
      printf( "  -Rows (-N) <int>:      exponent num, determines number of rows 2^num (default: 2^12 = 4096)\n" );
      printf( "  -Columns (-M) <int>:   exponent num, determines number of columns 2^num (default: 2^10 = 1024)\n" );
      printf( "  -Size (-S) <int>:      exponent num, determines total matrix size 2^num (default: 2^22 = 4096*1024 )\n" );
      printf( "  -nrepeat <int>:        number of repetitions (default: 100)\n" );
      printf( "  -help (-h):            print this message\n\n" );
      exit( 1 );
    }
  }

  // Check sizes.
  checkSizes( N, M, S, nrepeat );

  Kokkos::initialize( argc, argv );

  // EXERCISE give-away: Choose an Execution Space.
  // typedef Kokkos::Serial   ExecSpace;
  // typedef Kokkos::Threads  ExecSpace;
  // typedef Kokkos::OpenMP   ExecSpace;
  // typedef Kokkos::Cuda     ExecSpace;

  // EXERCISE: Choose device memory space.
  // typedef Kokkos::HostSpace     MemSpace;
  // typedef Kokkos::OpenMP        MemSpace;
  // typedef Kokkos::CudaSpace     MemSpace;
  // typedef Kokkos::CudaUVMSpace  MemSpace;

  // EXERCISE give-away: Choose a Layout.
  // EXERCISE: When exercise is correctly implemented, then
  //           either layout will generate the correct answer.
  //           However, performance will be different!

  // typedef Kokkos::LayoutLeft   Layout;
  // typedef Kokkos::LayoutRight  Layout;

  // EXERCISE give-away: Use a RangePolicy.
  // typedef Kokkos::RangePolicy<ExecSpace>  range_policy;

  // Allocate y, x vectors and Matrix A on device.
  // EXERCISE: Use MemSpace and Layout.
  typedef Kokkos::View<double*>   ViewVectorType;
  typedef Kokkos::View<double**>  ViewMatrixType;
  ViewVectorType y( "y", N );
  ViewVectorType x( "x", M );
  ViewMatrixType A( "A", N, M );

  // Create host mirrors of device views.
  ViewVectorType::HostMirror h_y = Kokkos::create_mirror_view( y );
  ViewVectorType::HostMirror h_x = Kokkos::create_mirror_view( x );
  ViewMatrixType::HostMirror h_A = Kokkos::create_mirror_view( A );

  // Initialize y vector on host.
  for ( int i = 0; i < N; ++i ) {
    h_y( i ) = 1;
  }

  // Initialize x vector on host.
  for ( int i = 0; i < M; ++i ) {
    h_x( i ) = 1;
  }

  // Initialize A matrix on host.
  for ( int j = 0; j < N; ++j ) {
    for ( int i = 0; i < M; ++i ) {
      h_A( j, i ) = 1;
    }
  }

  // Deep copy host views to device views.
  Kokkos::deep_copy( y, h_y );
  Kokkos::deep_copy( x, h_x );
  Kokkos::deep_copy( A, h_A );

  // Timer products.
  struct timeval begin, end;

  gettimeofday( &begin, NULL );

  for ( int repeat = 0; repeat < nrepeat; repeat++ ) {
    // Application: <y,Ax> = y^T*A*x
    double result = 0;

    // EXERCISE: Use Kokkos::RangePolicy<ExecSpace> to execute parallel_reduce
    //           in the correct space.
    Kokkos::parallel_reduce( N, KOKKOS_LAMBDA ( int j, double &update ) {
      double temp2 = 0;

      for ( int i = 0; i < M; ++i ) {
        temp2 += A( j, i ) * x( i );
      }

      update += y( j ) * temp2;
    }, result );
Ejemplo n.º 11
0
int main( int argc, char* argv[] )
{
  int N = -1;         // number of rows 2^12
  int M = -1;         // number of columns 2^10
  int S = -1;         // total size 2^22
  int E = -1;         // number of Elements
  int nrepeat = 100;  // number of repeats of the test

  // Read command line arguments.
  for ( int i = 0; i < argc; i++ ) {
    if ( ( strcmp( argv[ i ], "-N" ) == 0 ) || ( strcmp( argv[ i ], "-Rows" ) == 0 ) ) {
      N = pow( 2, atoi( argv[ ++i ] ) );
      printf( "  User N is %d\n", N );
    }
    else if ( ( strcmp( argv[ i ], "-M" ) == 0 ) || ( strcmp( argv[ i ], "-Columns" ) == 0 ) ) {
      M = pow( 2, atof( argv[ ++i ] ) );
      printf( "  User M is %d\n", M );
    }
    else if ( ( strcmp( argv[ i ], "-S" ) == 0 ) || ( strcmp( argv[ i ], "-Size" ) == 0 ) ) {
      S = pow( 2, atof( argv[ ++i ] ) );
      printf( "  User S is %d\n", S );
    }
    else if ( ( strcmp( argv[ i ], "-E" ) == 0 ) || ( strcmp( argv[ i ], "-Elements" ) == 0 ) ) {
      E = pow( 2, atof( argv[ ++i ] ) );
      printf( "  User E is %d\n", E );
    }
    else if ( strcmp( argv[ i ], "-nrepeat" ) == 0 ) {
      nrepeat = atoi( argv[ ++i ] );
    }
    else if ( ( strcmp( argv[ i ], "-h" ) == 0 ) || ( strcmp( argv[ i ], "-help" ) == 0 ) ) {
      printf( "  y^T*A*x Options:\n" );
      printf( "  -Rows (-N) <int>:      exponent num, determines number of rows 2^num (default: 2^8 = 256)\n" );
      printf( "  -Columns (-M) <int>:   exponent num, determines number of columns 2^num (default: 2^10 = 1024)\n" );
      printf( "  -Size (-S) <int>:      exponent num, determines total matrix size 2^num (default: 2^18 = 256*1024 )\n" );
      printf( "  -Elements (-E) <int>:  exponent num, determines number of elements 2^num (default: 2^10 = 1024 )\n" );
      printf( "  -nrepeat <int>:        number of repetitions (default: 100)\n" );
      printf( "  -help (-h):            print this message\n\n" );
      exit( 1 );
    }
  }

  // Check sizes.
  checkSizes( N, M, S, E, nrepeat );

  Kokkos::initialize( argc, argv );

  typedef Kokkos::LayoutRight  Layout;

  typedef Kokkos::RangePolicy<> range_policy;

  // Allocate y, x vectors and Matrix A on device.
  typedef Kokkos::View<double**, Layout>   ViewVectorType;
  typedef Kokkos::View<double***, Layout>  ViewMatrixType;
  ViewVectorType y( "y", E, N );
  ViewVectorType x( "x", E, M );
  ViewMatrixType A( "A", E, N, M );

  // Create host mirrors of device views.
  ViewVectorType::HostMirror h_y = Kokkos::create_mirror_view( y );
  ViewVectorType::HostMirror h_x = Kokkos::create_mirror_view( x );
  ViewMatrixType::HostMirror h_A = Kokkos::create_mirror_view( A );

  for ( int e = 0; e < E; e++ ) {
    // Initialize y vector on host.
    for ( int i = 0; i < N; ++i ) {
      h_y( e, i ) = 1;
    }

    // Initialize x vector on host.
    for ( int i = 0; i < M; ++i ) {
      h_x( e, i ) = 1;
    }

    // Initialize A matrix on host.
    for ( int j = 0; j < N; ++j ) {
      for ( int i = 0; i < M; ++i ) {
        h_A( e, j, i ) = 1;
      }
    }
  }

  // Deep copy host views to device views.
  Kokkos::deep_copy( y, h_y );
  Kokkos::deep_copy( x, h_x );
  Kokkos::deep_copy( A, h_A );

  typedef Kokkos::TeamPolicy<>               team_policy;
  typedef Kokkos::TeamPolicy<>::member_type  member_type;

  // Timer products.
  struct timeval begin, end;

  gettimeofday( &begin, NULL );

  for ( int repeat = 0; repeat < nrepeat; repeat++ ) {
    // Application: <y,Ax> = y^T*A*x
    double result = 0;

    Kokkos::parallel_reduce( team_policy( E, Kokkos::AUTO, 32 ), KOKKOS_LAMBDA ( const member_type &teamMember, double &update ) {
      const int e = teamMember.league_rank();
      double tempN = 0;

      Kokkos::parallel_reduce( Kokkos::TeamThreadRange( teamMember, N ), [&] ( const int j, double &innerUpdateN ) {
        double tempM = 0;

        Kokkos::parallel_reduce( Kokkos::ThreadVectorRange( teamMember, M ), [&] ( const int i, double &innerUpdateM ) {
          innerUpdateM += A( e, j, i ) * x( e, i );
        }, tempM );

        innerUpdateN += y( e, j ) * tempM;
      }, tempN );

      Kokkos::single( Kokkos::PerTeam( teamMember ), [&] () {
        update += tempN;
      });
    }, result );

    // Output result.
    if ( repeat == ( nrepeat - 1 ) ) {
      printf( "  Computed result for %d x %d x %d is %lf\n", N, M, E, result );
    }

    const double solution = (double) N *(double) M *(double) E;

    if ( result != solution ) {
      printf( "  Error: result( %lf ) != solution( %lf )\n", result, solution );
    }
  }
Ejemplo n.º 12
0
int main(int argc, char* argv[])
{

  int N = -1 ;       // number of rows 2^12
  int M = -1 ;       // number of columns 2^10
  int S = -1 ;      // total size 2^22
  int nrepeat = 100 ;    // number of repeats of the test

  // Read command line arguments
  for(int i=0; i<argc; i++) {
    if( (strcmp(argv[i], "-N") == 0) || (strcmp(argv[i], "-Rows") == 0) ) {
      N = pow( 2, atoi(argv[++i]) );
      printf("  User N is %d\n",N);
    } else if( (strcmp(argv[i], "-M") == 0) || (strcmp(argv[i], "-Columns") == 0)) {
      M = pow( 2, atof(argv[++i]) );
      printf("  User M is %d\n",M);
    } else if( (strcmp(argv[i], "-S") == 0) || (strcmp(argv[i], "-Size") == 0)) {
      S = pow( 2, atof(argv[++i]) );
      printf("  User S is %d\n",S);
    } else if( strcmp(argv[i], "-nrepeat") == 0) {
      nrepeat = atoi(argv[++i]);
    } else if( (strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "-help") == 0) ) {

      printf("  y^T*A*x Options:\n");
      printf("  -Rows (-N) <int>:      exponent num, determines number of rows 2^num (default: 2^12 = 4096)\n");
      printf("  -Columns (-M) <int>:   exponent num, determines number of columns 2^num (default: 2^10 = 1024)\n");
      printf("  -Size (-S) <int>:      exponent num, determines total matrix size 2^num (default: 2^22 = 4096*1024 )\n");
      printf("  -nrepeat <int>:        number of repetitions (default: 100)\n");
      printf("  -help (-h):            print this message\n\n");
      exit(1); }
  }

  //Check Sizes
  checkSizes( N, M, S, nrepeat );

  Kokkos::initialize(argc,argv);

  // typedef Kokkos::Serial   ExecSpace ;
  // typedef Kokkos::Threads  ExecSpace ;
  // typedef Kokkos::OpenMP   ExecSpace ;
  typedef Kokkos::Cuda        ExecSpace ;

  //EXERCISE: Choose device memory space
  // typedef Kokkos::HostSpace    MemSpace; 
  // typedef Kokkos::OpenMP       MemSpace; 
  typedef Kokkos::CudaSpace       MemSpace; 
  // typedef Kokkos::CudaUVMSpace MemSpace; 

  typedef Kokkos::LayoutLeft   Layout ;
  // typedef Kokkos::LayoutRight  Layout ;

  typedef Kokkos::RangePolicy<ExecSpace> range_policy ;

  // Allocate y, x vectors and Matrix A:
  // Device
  typedef Kokkos::View<double*, Layout, MemSpace>   ViewVectorType;
  typedef Kokkos::View<double**, Layout, MemSpace>   ViewMatrixType;
  ViewVectorType devy("devy", N);
  ViewVectorType devx("devx", M);
  ViewMatrixType devA("devA", N, M);

  //Host mirror
  ViewVectorType::HostMirror y =  Kokkos::create_mirror_view(devy);
  ViewVectorType::HostMirror x =  Kokkos::create_mirror_view(devx);
  ViewMatrixType::HostMirror A =  Kokkos::create_mirror_view(devA);

  // Initialize y vector on host
  for (int i = 0; i < N; ++i) {
    y( i ) = 1; 
  }

  // Initialize x vector on host
  for (int i = 0; i < M; ++i) {
    x( i ) = 1;
  }

  // Initialize A matrix, note 2D indexing computation on host
  for (int j = 0; j < N; ++j) {
    for ( int i = 0 ; i < M ; ++i ) {
      A( j , i ) = 1; 
    }
  }

  //Deep copy host view to device views
  Kokkos::deep_copy(devy, y);
  Kokkos::deep_copy(devx, x);
  Kokkos::deep_copy(devA, A);

  // EXERCISE: Use hierarchical parallel execution policy to initialize
  // EXERCISE hints:
  // typedef Kokkos::TeamPolicy<ExecSpace>               team_policy ;
  // typedef Kokkos::TeamPolicy<ExecSpace>::member_type  member_type ;

  // Timer products
  struct timeval begin,end;

  gettimeofday(&begin,NULL);

  for ( int repeat = 0; repeat < nrepeat; repeat++) {

    //Application: <y,Ax> = y^T*A*x
    // EXERCISE: Convert from range_policy to team_policy
    double result = 0;
    Kokkos::parallel_reduce( range_policy( 0, N ), KOKKOS_LAMBDA ( int j, double &update ) {
      // EXERCISE: Convert to nested Kokkos::parallel_reduce
      // EXERCISE hint: Kokkos::TeamThreadRange( ??? ) and [&]
      double temp2 = 0;
      for ( int i = 0 ; i < M ; ++i ) {
        temp2 += devA( j , i ) * devx( i );
      }
      // EXERCISE: Only one team member update the result
      update += devy( j ) * temp2;
    }, result );
Ejemplo n.º 13
0
int main( int argc, char* argv[] )
{
  int N = -1;         // number of rows 2^12
  int M = -1;         // number of columns 2^10
  int S = -1;         // total size 2^22
  int nrepeat = 100;  // number of repeats of the test

  // Read command line arguments.
  for ( int i = 0; i < argc; i++ ) {
    if ( ( strcmp( argv[ i ], "-N" ) == 0 ) || ( strcmp( argv[ i ], "-Rows" ) == 0 ) ) {
      N = pow( 2, atoi( argv[ ++i ] ) );
      printf( "  User N is %d\n", N );
    }
    else if ( ( strcmp( argv[ i ], "-M" ) == 0 ) || ( strcmp( argv[ i ], "-Columns" ) == 0 ) ) {
      M = pow( 2, atof( argv[ ++i ] ) );
      printf( "  User M is %d\n", M );
    }
    else if ( ( strcmp( argv[ i ], "-S" ) == 0 ) || ( strcmp( argv[ i ], "-Size" ) == 0 ) ) {
      S = pow( 2, atof( argv[ ++i ] ) );
      printf( "  User S is %d\n", S );
    }
    else if ( strcmp( argv[ i ], "-nrepeat" ) == 0 ) {
      nrepeat = atoi( argv[ ++i ] );
    }
    else if ( ( strcmp( argv[ i ], "-h" ) == 0 ) || ( strcmp( argv[ i ], "-help" ) == 0 ) ) {
      printf( "  y^T*A*x Options:\n" );
      printf( "  -Rows (-N) <int>:      exponent num, determines number of rows 2^num (default: 2^12 = 4096)\n" );
      printf( "  -Columns (-M) <int>:   exponent num, determines number of columns 2^num (default: 2^10 = 1024)\n" );
      printf( "  -Size (-S) <int>:      exponent num, determines total matrix size 2^num (default: 2^22 = 4096*1024 )\n" );
      printf( "  -nrepeat <int>:        number of repetitions (default: 100)\n" );
      printf( "  -help (-h):            print this message\n\n" );
      exit( 1 );
    }
  }

  // Check sizes.
  checkSizes( N, M, S, nrepeat );

  Kokkos::initialize( argc, argv );

  typedef Kokkos::DefaultExecutionSpace::array_layout  Layout;
  // typedef Kokkos::LayoutLeft   Layout;
  // typedef Kokkos::LayoutRight  Layout;

  typedef Kokkos::RangePolicy<> range_policy;

  // Allocate y, x vectors and Matrix A on device.
  typedef Kokkos::View<double*, Layout>   ViewVectorType;
  typedef Kokkos::View<double**, Layout>  ViewMatrixType;
  ViewVectorType y( "y", N );
  ViewVectorType x( "x", M );
  ViewMatrixType A( "A", N, M );

  // Create host mirrors of device views.
  ViewVectorType::HostMirror h_y = Kokkos::create_mirror_view( y );
  ViewVectorType::HostMirror h_x = Kokkos::create_mirror_view( x );
  ViewMatrixType::HostMirror h_A = Kokkos::create_mirror_view( A );

  // Initialize y vector on host.
  for ( int i = 0; i < N; ++i ) {
    h_y( i ) = 1;
  }

  // Initialize x vector on host.
  for ( int i = 0; i < M; ++i ) {
    h_x( i ) = 1;
  }

  // Initialize A matrix on host.
  for ( int j = 0; j < N; ++j ) {
    for ( int i = 0; i < M; ++i ) {
      h_A( j, i ) = 1;
    }
  }

  // Deep copy host views to device views.
  Kokkos::deep_copy( y, h_y );
  Kokkos::deep_copy( x, h_x );
  Kokkos::deep_copy( A, h_A );

  // EXERCISE: Use hierarchical parallel execution policy for calculation.
  // EXERCISE hints:
  // typedef Kokkos::TeamPolicy<>               team_policy;
  // typedef Kokkos::TeamPolicy<>::member_type  member_type;

  // Timer products.
  struct timeval begin, end;

  gettimeofday( &begin, NULL );

  for ( int repeat = 0; repeat < nrepeat; repeat++ ) {
    // Application: <y,Ax> = y^T*A*x
    double result = 0;

    // EXERCISE: Convert from range_policy to team_policy.
    Kokkos::parallel_reduce( range_policy( 0, N ), KOKKOS_LAMBDA ( int j, double &update ) {
      // EXERCISE: Convert to nested Kokkos::parallel_reduce.
      // EXERCISE hint: Kokkos::TeamThreadRange( ??? ) and [&].
      double temp2 = 0;

      for ( int i = 0; i < M; ++i ) {
        temp2 += A( j, i ) * x( i );
      }

      // EXERCISE: Only one team member update the result.
      update += y( j ) * temp2;
    }, result );
Ejemplo n.º 14
0
static lu_mem singlestep (lua_State *L) {
	global_State *g = G(L);
	switch (g->gcstate) {
	case GCSpause: {
		/* start to count memory traversed */
		g->GCmemtrav = g->strt.size * sizeof(GCObject*);
		lua_assert(!isgenerational(g));
		restartcollection(g);
		g->gcstate = GCSpropagate;
		return g->GCmemtrav;
	}
	case GCSpropagate: {
		if (g->gray) {
		lu_mem oldtrav = g->GCmemtrav;
		propagatemark(g);
		return g->GCmemtrav - oldtrav;  /* memory traversed in this step */
		}
		else {  /* no more `gray' objects */
		lu_mem work;
		int sw;
		g->gcstate = GCSatomic;  /* finish mark phase */
		g->GCestimate = g->GCmemtrav;  /* save what was counted */;
		work = atomic(L);  /* add what was traversed by 'atomic' */
		g->GCestimate += work;  /* estimate of total memory traversed */
		sw = entersweep(L);
		return work + sw * GCSWEEPCOST;
		}
	}
	case GCSsweepstring: {
		int i;
		for (i = 0; i < GCSWEEPMAX && g->sweepstrgc + i < g->strt.size; i++)
		sweepwholelist(L, &g->strt.hash[g->sweepstrgc + i]);
		g->sweepstrgc += i;
		if (g->sweepstrgc >= g->strt.size)  /* no more strings to sweep? */
		g->gcstate = GCSsweepudata;
		return i * GCSWEEPCOST;
	}
	case GCSsweepudata: {
		if (g->sweepfin) {
		g->sweepfin = sweeplist(L, g->sweepfin, GCSWEEPMAX);
		return GCSWEEPMAX*GCSWEEPCOST;
		}
		else {
		g->gcstate = GCSsweep;
		return 0;
		}
	}
	case GCSsweep: {
		if (g->sweepgc) {
		g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
		return GCSWEEPMAX*GCSWEEPCOST;
		}
		else {
		/* sweep main thread */
		GCObject *mt = obj2gco(g->mainthread);
		sweeplist(L, &mt, 1);
		checkSizes(L);
		g->gcstate = GCSpause;  /* finish collection */
		return GCSWEEPCOST;
		}
	}
	default: lua_assert(0); return 0;
	}
}
Ejemplo n.º 15
0
static void dragDivider(WMSplitView * sPtr, int clickX, int clickY)
{
	int divider, pos, ofs, done, dragging;
	int i, count;
	XEvent ev;
	WMScreen *scr;
	int minCoord, maxCoord, coord;

	if (sPtr->constrainProc) {
		updateConstraints(sPtr);
		checkSizes(sPtr);
		distributeOffsetFormEnd(sPtr, _GetSplitViewSize() - getTotalSize(sPtr));
		checkPositions(sPtr);
		updateSubviewsGeom(sPtr);
	}

	scr = sPtr->view->screen;
	divider = ofs = pos = done = 0;
	coord = (sPtr->flags.vertical) ? clickX : clickY;
	count = _GetSubviewsCount();
	if (count < 2)
		return;

	for (i = 0; i < count - 1; i++) {
		pos += _GetSizeAt(i) + DIVIDER_THICKNESS;
		if (coord < pos) {
			ofs = coord - pos + DIVIDER_THICKNESS;
			done = 1;
			break;
		}
		divider++;
	}

	if (!done)
		return;

	getMinMaxDividerCoord(sPtr, divider, &minCoord, &maxCoord);

	done = 0;
	dragging = 0;
	while (!done) {
		WMMaskEvent(scr->display, ButtonMotionMask | ButtonReleaseMask | ExposureMask, &ev);

		coord = (sPtr->flags.vertical) ? ev.xmotion.x : ev.xmotion.y;

		switch (ev.type) {
		case ButtonRelease:
			done = 1;
			if (dragging)
				drawDragingRectangle(sPtr, pos);
			break;

		case MotionNotify:
			if (dragging)
				drawDragingRectangle(sPtr, pos);
			if (coord - ofs < minCoord)
				pos = minCoord;
			else if (coord - ofs > maxCoord)
				pos = maxCoord;
			else
				pos = coord - ofs;
			drawDragingRectangle(sPtr, pos);
			dragging = 1;
			break;

		default:
			WMHandleEvent(&ev);
			break;
		}
	}

	if (dragging) {
		W_SplitViewSubview *p1, *p2;
		int totSize;

		p1 = _GetPSubviewStructAt(divider);
		p2 = _GetPSubviewStructAt(divider + 1);

		totSize = p1->size + DIVIDER_THICKNESS + p2->size;

		p1->size = pos - p1->pos;
		p2->size = totSize - p1->size - DIVIDER_THICKNESS;
		p2->pos = p1->pos + p1->size + DIVIDER_THICKNESS;

		resizeView(sPtr, p1->view, p1->size);
		moveView(sPtr, p2->view, p2->pos);
		resizeView(sPtr, p2->view, p2->size);
		sPtr->flags.subviewsWereManuallyMoved = 1;
	}
}
Ejemplo n.º 16
0
int main( int argc, char* argv[] )
{
  int N = -1;         // number of rows 2^12
  int M = -1;         // number of columns 2^10
  int S = -1;         // total size 2^22
  int nrepeat = 100;  // number of repeats of the test

  // Read command line arguments.
  for ( int i = 0; i < argc; i++ ) {
    if ( ( strcmp( argv[ i ], "-N" ) == 0 ) || ( strcmp( argv[ i ], "-Rows" ) == 0 ) ) {
      N = pow( 2, atoi( argv[ ++i ] ) );
      printf( "  User N is %d\n", N );
    }
    else if ( ( strcmp( argv[ i ], "-M" ) == 0 ) || ( strcmp( argv[ i ], "-Columns" ) == 0 ) ) {
      M = pow( 2, atof( argv[ ++i ] ) );
      printf( "  User M is %d\n", M );
    }
    else if ( ( strcmp( argv[ i ], "-S" ) == 0 ) || ( strcmp( argv[ i ], "-Size" ) == 0 ) ) {
      S = pow( 2, atof( argv[ ++i ] ) );
      printf( "  User S is %d\n", S );
    }
    else if ( strcmp( argv[ i ], "-nrepeat" ) == 0 ) {
      nrepeat = atoi( argv[ ++i ] );
    }
    else if ( ( strcmp( argv[ i ], "-h" ) == 0 ) || ( strcmp( argv[ i ], "-help" ) == 0 ) ) {
      printf( "  y^T*A*x Options:\n" );
      printf( "  -Rows (-N) <int>:      exponent num, determines number of rows 2^num (default: 2^12 = 4096)\n" );
      printf( "  -Columns (-M) <int>:   exponent num, determines number of columns 2^num (default: 2^10 = 1024)\n" );
      printf( "  -Size (-S) <int>:      exponent num, determines total matrix size 2^num (default: 2^22 = 4096*1024 )\n" );
      printf( "  -nrepeat <int>:        number of repetitions (default: 100)\n" );
      printf( "  -help (-h):            print this message\n\n" );
      exit( 1 );
    }
  }

  // Check sizes.
  checkSizes( N, M, S, nrepeat );

  // EXERCISE: Initialize Kokkos runtime.
  // Kokkos::initialize( argc, argv );

  // Allocate y, x vectors and Matrix A:
  double * const y = new double[ N ];
  double * const x = new double[ M ];
  double * const A = new double[ N * M ];

  // Initialize y vector.
  // EXERCISE: Convert outer loop to Kokkos::parallel_for.
  for ( int i = 0; i < N; ++i ) {
    y[ i ] = 1;
  }

  // Initialize x vector.
  // EXERCISE: Convert outer loop to Kokkos::parallel_for.
  for ( int i = 0; i < M; ++i ) {
    x[ i ] = 1;
  }

  // Initialize A matrix, note 2D indexing computation.
  // EXERCISE: Convert outer loop to Kokkos::parallel_for.
  for ( int j = 0; j < N; ++j ) {
    for ( int i = 0; i < M; ++i ) {
      A[ j * M + i ] = 1;
    }
  }

  // Timer products.
  struct timeval begin, end;

  gettimeofday( &begin, NULL );

  for ( int repeat = 0; repeat < nrepeat; repeat++ ) {
    // Application: <y,Ax> = y^T*A*x
    double result = 0;

    // EXERCISE: Convert outer loop to Kokkos::parallel_reduce.
    for ( int j = 0; j < N; ++j ) {
      double temp2 = 0;

      for ( int i = 0; i < M; ++i ) {
        temp2 += A[ j * M + i ] * x[ i ];
      }

      result += y[ j ] * temp2;
    }

    // Output result.
    if ( repeat == ( nrepeat - 1 ) ) {
      printf( "  Computed result for %d x %d is %lf\n", N, M, result );
    }

    const double solution = (double) N * (double) M;

    if ( result != solution ) {
      printf( "  Error: result( %lf ) != solution( %lf )\n", result, solution );
    }
  }

  gettimeofday( &end, NULL );

  // Calculate time.
  double time = 1.0 * ( end.tv_sec - begin.tv_sec ) +
                1.0e-6 * ( end.tv_usec - begin.tv_usec );

  // Calculate bandwidth.
  // Each matrix A row (each of length M) is read once.
  // The x vector (of length M) is read N times.
  // The y vector (of length N) is read once.
  // double Gbytes = 1.0e-9 * double( sizeof(double) * ( 2 * M * N + N ) );
  double Gbytes = 1.0e-9 * double( sizeof(double) * ( M + M * N + N ) );

  // Print results (problem size, time and bandwidth in GB/s).
  printf( "  N( %d ) M( %d ) nrepeat ( %d ) problem( %g MB ) time( %g s ) bandwidth( %g GB/s )\n",
          N, M, nrepeat, Gbytes * 1000, time, Gbytes * nrepeat / time );

  delete[] A;
  delete[] y;
  delete[] x;

  // EXERCISE: finalize Kokkos runtime
  // Kokkos::finalize();

  return 0;
}
Ejemplo n.º 17
0
void luaC_collectgarbage (lua_State *L) {
  mark(L);
  luaC_sweep(L, 0);
  checkSizes(L);
  luaC_callGCTM(L);
}
Ejemplo n.º 18
0
void StaticMapLayer::checkArguments(const QVector<QVector<StaticMapObject*>> & staticObjects) const
{
    checkSizes(staticObjects);
    checkForNullptr(staticObjects);
    checkStairs(staticObjects);
}
Ejemplo n.º 19
0
int main(int argc, char* argv[])
{

  int N = -1 ;       // number of rows 2^12
  int M = -1 ;       // number of columns 2^10
  int S = -1 ;      // total size 2^22
  int nrepeat = 100 ;    // number of repeats of the test

  // Read command line arguments
  for(int i=0; i<argc; i++) {
    if( (strcmp(argv[i], "-N") == 0) || (strcmp(argv[i], "-Rows") == 0) ) {
      N = pow( 2, atoi(argv[++i]) );
      printf("  User N is %d\n",N);
    } else if( (strcmp(argv[i], "-M") == 0) || (strcmp(argv[i], "-Columns") == 0)) {
      M = pow( 2, atof(argv[++i]) );
      printf("  User M is %d\n",M);
    } else if( (strcmp(argv[i], "-S") == 0) || (strcmp(argv[i], "-Size") == 0)) {
      S = pow( 2, atof(argv[++i]) );
      printf("  User S is %d\n",S);
    } else if( strcmp(argv[i], "-nrepeat") == 0) {
      nrepeat = atoi(argv[++i]);
    } else if( (strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "-help") == 0) ) {

      printf("  y^T*A*x Options:\n");
      printf("  -Rows (-N) <int>:      exponent num, determines number of rows 2^num (default: 2^12 = 4096)\n");
      printf("  -Columns (-M) <int>:   exponent num, determines number of columns 2^num (default: 2^10 = 1024)\n");
      printf("  -Size (-S) <int>:      exponent num, determines total matrix size 2^num (default: 2^22 = 4096*1024 )\n");
      printf("  -nrepeat <int>:        number of repetitions (default: 100)\n");
      printf("  -help (-h):            print this message\n\n");
      exit(1); }
  }

  //Check Sizes
  checkSizes( N, M, S, nrepeat );

  Kokkos::initialize(argc,argv);

  //EXERCISE: Create two types of views, one for device
  //  the other a mirror to host view
  
  // 1. Device Views
  // typedef Kokkos::View<double*>   ViewVectorType;
  // typedef Kokkos::View<double**>   ViewMatrixType;
  // ViewVectorType devy("devy", N);
  // ViewVectorType devx("devx", M);
  // ViewMatrixType devA("devA", N, M);

  // 2. Host View (mirrors)
  // ViewVectorType::HostMirror y =  Kokkos::create_mirror_view(devy);
  // ViewVectorType::HostMirror x =  Kokkos::create_mirror_view(devx);
  // ViewMatrixType::HostMirror A =  Kokkos::create_mirror_view(devA);

  //EXERCISE: This no longer needs allocation after views introduced...
  // Hint: If arrays are not allocated, they also do not need to be deallocated below
  // Allocate y, x vectors and Matrix A:
  double * const y = new double[ N ];
  double * const x = new double[ M ];
  double * const A = new double[ N * M ];

  // Initialize y vector on host
  // EXERCISE: Convert y to 1D View's member access API: x(i)
  for (int i = 0; i < N; ++i) {
    y[i] = 1;
  }

  // Initialize x vector on host
  // EXERCISE: Convert x to 1D View's member access API: x(i)
  for (int i = 0; i < M; ++i) {
    x[i] = 1;
  }

  // Initialize A matrix on host
  // EXERCISE: convert 'A' to use View's member access API: A(j,i)
  for (int j = 0; j < N; ++j) {
    for ( int i = 0 ; i < M ; ++i ) {
      A[ j * M + i ] = 1; 
    }
  }

  //EXERCISE: Perform deep copy of host views to device views

  // Timer products
  struct timeval begin,end;

  gettimeofday(&begin,NULL);

  for ( int repeat = 0; repeat < nrepeat; repeat++) {

    //Application: <y,Ax> = y^T*A*x
    double result = 0;
    Kokkos::parallel_reduce( N, KOKKOS_LAMBDA ( int j, double &update ) {
      double temp2 = 0;
      //EXERCISE: Replace host variables with device variables
      for ( int i = 0 ; i < M ; ++i ) {
        temp2 += A[ j * M + i ] * x[ i ];
      }
      update += y[ j ] * temp2;
    }, result );
Ejemplo n.º 20
0
int main(int argc, char* argv[])
{

  int N = -1 ;       // number of rows 2^12
  int M = -1 ;       // number of columns 2^10
  int S = -1 ;      // total size 2^22
  int nrepeat = 100 ;    // number of repeats of the test

  // Read command line arguments
  for(int i=0; i<argc; i++) {
    if( (strcmp(argv[i], "-N") == 0) || (strcmp(argv[i], "-Rows") == 0) ) {
      N = pow( 2, atoi(argv[++i]) );
      printf("  User N is %d\n",N);
    } else if( (strcmp(argv[i], "-M") == 0) || (strcmp(argv[i], "-Columns") == 0)) {
      M = pow( 2, atof(argv[++i]) );
      printf("  User M is %d\n",M);
    } else if( (strcmp(argv[i], "-S") == 0) || (strcmp(argv[i], "-Size") == 0)) {
      S = pow( 2, atof(argv[++i]) );
      printf("  User S is %d\n",S);
    } else if( strcmp(argv[i], "-nrepeat") == 0) {
      nrepeat = atoi(argv[++i]);
    } else if( (strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "-help") == 0) ) {

      printf("  y^T*A*x Options:\n");
      printf("  -Rows (-N) <int>:      exponent num, determines number of rows 2^num (default: 2^12 = 4096)\n");
      printf("  -Columns (-M) <int>:   exponent num, determines number of columns 2^num (default: 2^10 = 1024)\n");
      printf("  -Size (-S) <int>:      exponent num, determines total matrix size 2^num (default: 2^22 = 4096*1024 )\n");
      printf("  -nrepeat <int>:        number of repetitions (default: 100)\n");
      printf("  -help (-h):            print this message\n\n");

      exit(1); }
  }

  //Check Sizes
  checkSizes( N, M, S, nrepeat );

  Kokkos::initialize(argc,argv);

  // Allocate y, x vectors and Matrix A:
  // Device
  typedef Kokkos::View<double*>   ViewVectorType;
  typedef Kokkos::View<double**>   ViewMatrixType;
  ViewVectorType y("y", N);
  ViewVectorType x("x", M);
  ViewMatrixType A("A", N, M);

  ViewVectorType::HostMirror h_y =  Kokkos::create_mirror_view(y);
  ViewVectorType::HostMirror h_x =  Kokkos::create_mirror_view(x);
  ViewMatrixType::HostMirror h_A =  Kokkos::create_mirror_view(A);

  // Initialize y vector on host
  for (int i = 0; i < N; ++i) {
    h_y( i ) = 1;
  }

  // Initialize x vector on host
  for (int i = 0; i < M; ++i) {
    h_x( i ) = 1;
  }

  // Initialize A matrix, note 2D indexing computation on host
  for (int j = 0; j < N; ++j) {
    for ( int i = 0 ; i < M ; ++i ) {
      h_A( j , i ) = 1;
    }
  }

  Kokkos::deep_copy(y,h_y);
  Kokkos::deep_copy(x,h_x);
  Kokkos::deep_copy(A,h_A);

  // Timer products
  struct timeval begin,end;

  gettimeofday(&begin,NULL);

  for ( int repeat = 0; repeat < nrepeat; repeat++) {

    //Application: <y,Ax> = y^T*A*x
    double result = 0;
    Kokkos::parallel_reduce( N, KOKKOS_LAMBDA ( int j, double &update ) {
      double temp2 = 0;
      for ( int i = 0 ; i < M ; ++i ) {
        temp2 += A( j , i ) * x( i );
      }
      update += y( j ) * temp2;
    }, result );
Ejemplo n.º 21
0
int main(int argc, char* argv[])
{

  int N = -1 ;       // number of rows 2^12
  int M = -1 ;       // number of columns 2^10
  int S = -1 ;      // total size 2^22
  int nrepeat = 100 ;    // number of repeats of the test

  // Read command line arguments
  for(int i=0; i<argc; i++) {
    if( (strcmp(argv[i], "-N") == 0) || (strcmp(argv[i], "-Rows") == 0) ) {
      N = pow( 2, atoi(argv[++i]) );
      printf("  User N is %d\n",N);
    } else if( (strcmp(argv[i], "-M") == 0) || (strcmp(argv[i], "-Columns") == 0)) {
      M = pow( 2, atof(argv[++i]) );
      printf("  User M is %d\n",M);
    } else if( (strcmp(argv[i], "-S") == 0) || (strcmp(argv[i], "-Size") == 0)) {
      S = pow( 2, atof(argv[++i]) );
      printf("  User S is %d\n",S);
    } else if( strcmp(argv[i], "-nrepeat") == 0) {
      nrepeat = atoi(argv[++i]);
    } else if( (strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "-help") == 0) ) {

      printf("  y^T*A*x Options:\n");
      printf("  -Rows (-N) <int>:      exponent num, determines number of rows 2^num (default: 2^12 = 4096)\n");
      printf("  -Columns (-M) <int>:   exponent num, determines number of columns 2^num (default: 2^10 = 1024)\n");
      printf("  -Size (-S) <int>:      exponent num, determines total matrix size 2^num (default: 2^22 = 4096*1024 )\n");
      printf("  -nrepeat <int>:        number of repetitions (default: 100)\n");
      printf("  -help (-h):            print this message\n\n");
      exit(1); }
  }

  //Check Sizes
  checkSizes( N, M, S, nrepeat );

  Kokkos::initialize(argc,argv);

  // typedef Kokkos::DefaultExecutionSpace::array_layout Layout;
  // typedef Kokkos::LayoutLeft   Layout ;
  typedef Kokkos::LayoutRight  Layout ;

  // Allocate y, x vectors and Matrix A:
  // Device
  typedef Kokkos::View<double*, Layout>   ViewVectorType;
  typedef Kokkos::View<double**, Layout>   ViewMatrixType;
  ViewVectorType y("y", N);
  ViewVectorType x("x", M);
  ViewMatrixType A("A", N, M);

  //Host mirror
  ViewVectorType::HostMirror h_y =  Kokkos::create_mirror_view(y);
  ViewVectorType::HostMirror h_x =  Kokkos::create_mirror_view(x);
  ViewMatrixType::HostMirror h_A =  Kokkos::create_mirror_view(A);

  // Initialize y vector on host
  for (int i = 0; i < N; ++i) {
    h_y( i ) = 1;
  }

  // Initialize x vector on host
  for (int i = 0; i < M; ++i) {
    h_x( i ) = 1;
  }

  // Initialize A matrix, note 2D indexing computation on host
  for (int j = 0; j < N; ++j) {
    for ( int i = 0 ; i < M ; ++i ) {
      h_A( j , i ) = 1;
    }
  }

  //Deep copy host view to device views
  Kokkos::deep_copy(y, h_y);
  Kokkos::deep_copy(x, h_x);
  Kokkos::deep_copy(A, h_A);

  typedef Kokkos::TeamPolicy<>               team_policy ;
  typedef Kokkos::TeamPolicy<>::member_type  member_type ;

  // Timer products
  struct timeval begin,end;

  gettimeofday(&begin,NULL);

  for ( int repeat = 0; repeat < nrepeat; repeat++) {

    //Application: <y,Ax> = y^T*A*x
    double result = 0;
    Kokkos::parallel_reduce( team_policy( N , Kokkos::AUTO ), KOKKOS_LAMBDA ( const member_type& teamMember, double &update ) {
      const int j = teamMember.league_rank();
      double temp2 = 0;
      Kokkos::parallel_reduce( Kokkos::TeamThreadRange( teamMember, M ), [&] (const int i, double &innerUpdate ) {
        innerUpdate += A( j , i ) * x( i );
      }, temp2);
      if ( teamMember.team_rank() == 0 )
        update += y( j ) * temp2;
    }, result );

    //Output result
    if ( repeat == (nrepeat - 1) )
      printf("  Computed result for %d x %d is %lf\n", N, M, result);
    const double solution = (double)N *(double)M;

    if ( result != solution ) {
      printf("  Error: result( %lf ) != solution( %lf )\n",result,solution);
    }
  }