Ejemplo n.º 1
0
void test()
{
	MazeGame game;
	Maze* pMaze = game.CreateMaze();
	pMaze->show();
	printSep();

	//Factory method
	MazeGame_FactoryMethod_Enchanted game_fme;
	pMaze = game_fme.CreateMaze();
	pMaze->show();
	printSep();

	//Abstract Factory
	MazeGame_AbstractFactory game_af;
	EnchantedMazeFactory factory;
	pMaze = game_af.CreateMaze(factory);
	pMaze->show();
	printSep();

	//Builder
	MazeGame_Builder game_builder;
	StandardMazeBuilder builder;
	pMaze = game_builder.CreateMaze(builder);
	pMaze->show();
	printSep();
}
void memcpytest2_sizes(size_t maxElem=0, size_t offset=0)
{
    printSep();
    printf ("test: %s<%s>\n", __func__,  TYPENAME(T));

    int deviceId;
    HIPCHECK(hipGetDevice(&deviceId));

    size_t free, total;
    HIPCHECK(hipMemGetInfo(&free, &total));

    if (maxElem == 0) {
        maxElem = free/sizeof(T)/5;
    }

    printf ("  device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB)    maxSize=%6.1fMB offset=%lu\n", 
            deviceId, free, (float)(free/1024.0/1024.0), total, (float)(total/1024.0/1024.0), maxElem*sizeof(T)/1024.0/1024.0, offset);

    for (size_t elem=64; elem+offset<=maxElem; elem*=2) {
        HIPCHECK ( hipDeviceReset() );
        memcpytest2<T>(elem+offset, 0, 1, 1, 0);  // unpinned host
        HIPCHECK ( hipDeviceReset() );
        memcpytest2<T>(elem+offset, 1, 1, 1, 0);  // pinned host
    }
}
Ejemplo n.º 3
0
static int rprint(int dep, int padding, Directory *dir, int gap[]) {
	Directory *u = dir->childDir;
	gap[dep] = padding;
	if (dir->childDir != NULL) {
		printSep(dep, gap, 0);
		puts("  |");
	}
	while (u != NULL) {
		printSep(dep, gap, 0);
		printf("  +- %s\n", u->name);
		rprint(dep+1, padding+2, u, gap);
		u = u->silbingDir;
		if (u != NULL) {
			printSep(dep, gap, 0);
			puts("  |");
		}
	}
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
    HipTest::parseStandardArguments(argc, argv, true);

    printf ("info: set device to %d\n", p_gpuDevice);
    HIPCHECK(hipSetDevice(p_gpuDevice));

    if (p_tests & 0x1) {
        printf ("\n\n=== tests&1 (types)\n");
        printSep();
        HIPCHECK ( hipDeviceReset() );
        size_t width = N/6;
        size_t height = N/6;
        memcpy2Dtest<float>(321, 211, 0);
        memcpy2Dtest<double>(322, 211, 0);
        memcpy2Dtest<char>(320, 211, 0);
        memcpy2Dtest<int>(323, 211, 0);
        printf ("===\n\n\n");

        printf ("\n\n=== tests&1 (types)\n");
        printSep();
        // 2D
        memcpyArraytest<float>(320, 211, 0, 0);
        memcpyArraytest<unsigned int>(322, 211, 0, 0);
        memcpyArraytest<int>(320, 211, 0, 0);
        memcpyArraytest<float>(320, 211, 0, 1);
        memcpyArraytest<float>(322, 211, 0, 1);
        memcpyArraytest<int>(320, 211, 0, 1);
        printSep();
        // 1D
        memcpyArraytest<float>(320, 1, 0);
        memcpyArraytest<unsigned int>(322, 1, 0);
        memcpyArraytest<int>(320, 1, 0);
        printf ("===\n\n\n");
    }

    if (p_tests & 0x4) {
        printf ("\n\n=== tests&4 (test sizes and offsets)\n");
        printSep();
        HIPCHECK ( hipDeviceReset() );
        printSep();
        memcpyArraytest_size<float>(0,0);
        printSep();
        memcpyArraytest_size<float>(0,64);
        printSep();
        memcpyArraytest_size<float>(1024*1024,13);
        printSep();
        memcpyArraytest_size<float>(1024*1024,50);
    }

    passed();

}
Ejemplo n.º 5
0
inline void casadi_math<T>::print(unsigned char op, std::ostream &stream, const std::string& x, const std::string& y){
  if(ndeps(op)==2){
    printPre(op,stream);
    stream << x;
    printSep(op,stream);
    stream << y;
    printPost(op,stream);
  } else {
    printPre(op,stream);
    stream << x;
    printPost(op,stream);
  }
}
void memcpytest2_for_type(size_t numElements)
{
    printSep();

    for (int usePinnedHost =0; usePinnedHost<=1; usePinnedHost++) {
        for (int useHostToHost =0; useHostToHost<=1; useHostToHost++) {  // TODO
            for (int useDeviceToDevice =0; useDeviceToDevice<=1; useDeviceToDevice++) {
                for (int useMemkindDefault =0; useMemkindDefault<=1; useMemkindDefault++) {
                    memcpytest2<T>(numElements, usePinnedHost, useHostToHost, useDeviceToDevice, useMemkindDefault);
                }
            }
        }
    }
}
void multiThread_1(bool serialize, bool usePinnedHost)
{
    printSep();
    printf ("test: %s<%s> serialize=%d usePinnedHost=%d\n", __func__,  TYPENAME(T), serialize, usePinnedHost);
    std::thread t1 (memcpytest2<T>,N, usePinnedHost,0,0,0);
    if (serialize) {
        t1.join();
    }

    
    std::thread t2 (memcpytest2<T>,N, usePinnedHost,0,0,0);
    if (serialize) {
        t2.join();
    }

    if (!serialize) {
        t1.join();
        t2.join();
    }
}
int main(int argc, char *argv[])
{
    HipTest::parseStandardArguments(argc, argv, true);

    printf ("info: set device to %d\n", p_gpuDevice);
    HIPCHECK(hipSetDevice(p_gpuDevice));


    if (p_tests & 0x1) {
        printf ("\n\n=== tests&1 (types and different memcpy kinds (H2D, D2H, H2H, D2D)\n");
        HIPCHECK ( hipDeviceReset() );
        memcpytest2_for_type<float>(N);
        memcpytest2_for_type<double>(N);
        memcpytest2_for_type<char>(N);
        memcpytest2_for_type<int>(N);
        printf ("===\n\n\n");
    }


    if (p_tests & 0x2) {
        // Some tests around the 64MB boundary which have historically shown issues:
        printf ("\n\n=== tests&0x2 (64MB boundary)\n");
#if 0
        // These all pass:
        memcpytest2<float>(15*1024*1024, 1, 0, 0, 0);  
        memcpytest2<float>(16*1024*1024, 1, 0, 0, 0);  
        memcpytest2<float>(16*1024*1024+16*1024,  1, 0, 0, 0);  
#endif
        // Just over 64MB:
        memcpytest2<float>(16*1024*1024+512*1024,  1, 0, 0, 0);  
        memcpytest2<float>(17*1024*1024+1024,  1, 0, 0, 0);  
        memcpytest2<float>(32*1024*1024, 1, 0, 0, 0);  
        memcpytest2<float>(32*1024*1024, 0, 0, 0, 0);  
        memcpytest2<float>(32*1024*1024, 1, 1, 1, 0);  
        memcpytest2<float>(32*1024*1024, 1, 1, 1, 0);  
    }


    if (p_tests & 0x4) {
        printf ("\n\n=== tests&4 (test sizes and offsets)\n");
        HIPCHECK ( hipDeviceReset() );
        printSep();
        memcpytest2_sizes<float>(0,0);
        printSep();
        memcpytest2_sizes<float>(0,64);
        printSep();
        memcpytest2_sizes<float>(1024*1024, 13);
        printSep();
        memcpytest2_sizes<float>(1024*1024, 50);
    }

    if (p_tests & 0x8) {
        printf ("\n\n=== tests&8\n");
        HIPCHECK ( hipDeviceReset() );
        printSep();

        // Simplest cases: serialize the threads, and also used pinned memory:
        // This verifies that the sub-calls to memcpytest2 are correct.
        multiThread_1<float>(true, true); 

        // Serialize, but use unpinned memory to stress the unpinned memory xfer path.
        multiThread_1<float>(true, false);

        // Remove serialization, so two threads are performing memory copies in parallel.
        multiThread_1<float>(false, true);

        // Remove serialization, and use unpinned.
        multiThread_1<float>(false, false); // TODO
        printf ("===\n\n\n");
    }


    passed();

}