Esempio n. 1
0
void supervision_reset(void)
{
	//fprintf(log_get(), "supervision: reset\n");


	memorymap_reset();
	io_reset();
	gpu_reset();
	timer_reset();
	controls_reset();
	/*sound_reset();*/
	interrupts_reset();

	Reset6502(&m6502_registers);
}
Esempio n. 2
0
void autoencoder_GPU::train(){
	for(int epoch = 0; epoch < nEpochNum; epoch++){
		dataprovider->reset();
		printf("Epoch %d\n", epoch + 1);
		gpu_reset(gpu_env, reset, d_error, nLayerSize0 * nVectorPerBatch, NULL);	

		for(int batch = 0; batch < nBatchNum; batch++){
			dataprovider->getNextDeviceBatch(d_layer0act);
			fprop();
			/*
			if(batch == 1){
				gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_bias0, CL_TRUE, 0, nLayerSize1 * sizeof(floatType), (void*)bias0, 0, NULL, NULL);
				ofstream tempStream;
				tempStream.open("../log/bias.log", ios_base::trunc);
				for(unsigned i = 0; i < nLayerSize1; i++){
					tempStream << bias0[i] << ',';
					if((i + 1) % nLayerSize1 == 0){
						tempStream << endl;
					}
				}
				tempStream.close();
			}

			if(batch == 1){
				gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_weight0, CL_TRUE, 0, nLayerSize0 * nLayerSize1 * sizeof(floatType), (void*)weight0, 0, NULL, NULL);
				ofstream tempStream;
				tempStream.open("../log/weight.log", ios_base::trunc);
				for(unsigned i = 0; i < nLayerSize0 * nLayerSize1; i++){
					tempStream << weight0[i] << ',';
					if((i + 1) % nLayerSize0 == 0){
						tempStream << endl;
					}
				}
				tempStream.close();
			}

			if(batch == 1){
				gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_layer1act, CL_TRUE, 0, nVectorPerBatch * nLayerSize1 * sizeof(floatType), (void*)layer1act, 0, NULL, NULL);
				ofstream tempStream;
				tempStream.open("../log/activation.log", ios_base::trunc);
				for(unsigned i = 0; i < nVectorPerBatch * nLayerSize1; i++){
					tempStream << layer1act[i] << ',';
					if((i + 1) % nVectorPerBatch == 0){
						tempStream << endl;
					}
				}
				tempStream.close();
				// exit(0);
			}
			*/

			gpu_squareError(gpu_env, squareError, d_layer8act, d_layer0act, d_error, nLayerSize0 * nVectorPerBatch);
			bprop();
			update();
		
			/*
			if(!epoch){
				double errsum = 0.0;
				gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_error, CL_TRUE, 0, nLayerSize0 * nVectorPerBatch * sizeof(floatType), (void*)error, 0, NULL, NULL);
				for(int i = 0; i < nLayerSize8 * nVectorPerBatch; i++){
					errsum += error[i];
				}
				printf("Epoch %d Batch %d Error %f\n", epoch + 1, batch + 1, errsum);
			}
			*/

		}

		double errsum = 0.0;
		gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_error, CL_TRUE, 0, nLayerSize0 * nVectorPerBatch * sizeof(floatType), (void*)error, 0, NULL, NULL);
		for(int i = 0; i < nLayerSize8 * nVectorPerBatch; i++){
			errsum += error[i];
		}
		printf("Epoch %d Error %f\n", epoch + 1, errsum);

		ofstream fout;
		fout.open("../log/errorLog.txt", ios_base::app);
		struct timeval now;
		gettimeofday(&now, NULL);
		fout << now.tv_sec << ',' << errsum << endl;
		fout.close();
	}

	ofstream fout;

	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_weight0, CL_TRUE, 0, nLayerSize0 * nLayerSize1 * sizeof(floatType), (void*)weight0, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_weight1, CL_TRUE, 0, nLayerSize1 * nLayerSize2 * sizeof(floatType), (void*)weight1, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_weight2, CL_TRUE, 0, nLayerSize2 * nLayerSize3 * sizeof(floatType), (void*)weight2, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_weight3, CL_TRUE, 0, nLayerSize3 * nLayerSize4 * sizeof(floatType), (void*)weight3, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_weight4, CL_TRUE, 0, nLayerSize4 * nLayerSize5 * sizeof(floatType), (void*)weight4, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_weight5, CL_TRUE, 0, nLayerSize5 * nLayerSize6 * sizeof(floatType), (void*)weight5, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_weight6, CL_TRUE, 0, nLayerSize6 * nLayerSize7 * sizeof(floatType), (void*)weight6, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_weight7, CL_TRUE, 0, nLayerSize7 * nLayerSize8 * sizeof(floatType), (void*)weight7, 0, NULL, NULL);

	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_bias0, CL_TRUE, 0, nLayerSize1 * sizeof(floatType), (void*)bias0, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_bias1, CL_TRUE, 0, nLayerSize2 * sizeof(floatType), (void*)bias1, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_bias2, CL_TRUE, 0, nLayerSize3 * sizeof(floatType), (void*)bias2, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_bias3, CL_TRUE, 0, nLayerSize4 * sizeof(floatType), (void*)bias3, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_bias4, CL_TRUE, 0, nLayerSize5 * sizeof(floatType), (void*)bias4, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_bias5, CL_TRUE, 0, nLayerSize6 * sizeof(floatType), (void*)bias5, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_bias6, CL_TRUE, 0, nLayerSize7 * sizeof(floatType), (void*)bias6, 0, NULL, NULL);
	gpu_env.status = clEnqueueReadBuffer(gpu_env.queue, d_bias7, CL_TRUE, 0, nLayerSize8 * sizeof(floatType), (void*)bias7, 0, NULL, NULL);

	fout.open("../data/autoencoderWeight.dat", ios_base::binary | ios_base::trunc);
	fout.write((char*)weight0, nLayerSize0 * nLayerSize1 * sizeof(floatType));
	fout.write((char*)weight1, nLayerSize1 * nLayerSize2 * sizeof(floatType));
	fout.write((char*)weight2, nLayerSize2 * nLayerSize3 * sizeof(floatType));
	fout.write((char*)weight3, nLayerSize3 * nLayerSize4 * sizeof(floatType));
	fout.write((char*)weight4, nLayerSize4 * nLayerSize5 * sizeof(floatType));
	fout.write((char*)weight5, nLayerSize5 * nLayerSize6 * sizeof(floatType));
	fout.write((char*)weight6, nLayerSize6 * nLayerSize7 * sizeof(floatType));
	fout.write((char*)weight7, nLayerSize7 * nLayerSize8 * sizeof(floatType));
	fout.close();
	fout.open("../data/autoencoderBias.dat", ios_base::binary | ios_base::trunc);
	fout.write((char*)bias0, nLayerSize1 * sizeof(floatType));
	fout.write((char*)bias1, nLayerSize2 * sizeof(floatType));
	fout.write((char*)bias2, nLayerSize3 * sizeof(floatType));
	fout.write((char*)bias3, nLayerSize4 * sizeof(floatType));
	fout.write((char*)bias4, nLayerSize5 * sizeof(floatType));
	fout.write((char*)bias5, nLayerSize6 * sizeof(floatType));
	fout.write((char*)bias6, nLayerSize7 * sizeof(floatType));
	fout.write((char*)bias7, nLayerSize8 * sizeof(floatType));
	fout.close();
		
}
Esempio n. 3
0
void gameboy_init()
{
    /* init global values */
    // global_init();

    /* init z80 */
    z80_init();

    /* init cycles syncronizer */
    cycles_init();

    /* init input */
    input_init();

    /* init timer */
    timer_init();

    /* init serial */
    serial_init();

    /* init sound (this will start audio thread) */
    sound_init();

    /* reset GPU counters */
    gpu_reset();

    /* reset to default values */
    mmu_write_no_cyc(0xFF05, 0x00);
    mmu_write_no_cyc(0xFF06, 0x00);
    mmu_write_no_cyc(0xFF07, 0x00);
    mmu_write_no_cyc(0xFF10, 0x80);
    mmu_write_no_cyc(0xFF11, 0xBF);
    mmu_write_no_cyc(0xFF12, 0xF3);
    mmu_write_no_cyc(0xFF14, 0xBF);
    mmu_write_no_cyc(0xFF16, 0x3F);
    mmu_write_no_cyc(0xFF17, 0x00);
    mmu_write_no_cyc(0xFF19, 0xBF);
    mmu_write_no_cyc(0xFF1A, 0x7F);
    mmu_write_no_cyc(0xFF1B, 0xFF);
    mmu_write_no_cyc(0xFF1C, 0x9F);
    mmu_write_no_cyc(0xFF1E, 0xBF);
    mmu_write_no_cyc(0xFF20, 0xFF);
    mmu_write_no_cyc(0xFF21, 0x00);
    mmu_write_no_cyc(0xFF22, 0x00);
    mmu_write_no_cyc(0xFF23, 0xBF);
    mmu_write_no_cyc(0xFF24, 0x77);
    mmu_write_no_cyc(0xFF25, 0xF3);
    mmu_write_no_cyc(0xFF26, 0xF1);
    mmu_write_no_cyc(0xFF40, 0x91);
    mmu_write_no_cyc(0xFF41, 0x80);
    mmu_write_no_cyc(0xFF42, 0x00);
    mmu_write_no_cyc(0xFF43, 0x00);
    mmu_write_no_cyc(0xFF44, 0x00);
    mmu_write_no_cyc(0xFF45, 0x00);
    mmu_write_no_cyc(0xFF47, 0xFC);
    mmu_write_no_cyc(0xFF48, 0xFF);
    mmu_write_no_cyc(0xFF49, 0xFF);
    mmu_write_no_cyc(0xFF4A, 0x00);
    mmu_write_no_cyc(0xFF4B, 0x00);
    mmu_write_no_cyc(0xFF98, 0xDC);
    mmu_write_no_cyc(0xFFFF, 0x00);
    mmu_write_no_cyc(0xC000, 0x08);
    mmu_write_no_cyc(0xFFFE, 0x69);

    if (global_cgb)
        state.a = 0x11;
    else
        state.a = 0x00;

    state.b = 0x00;
    state.c = 0x13;
    state.d = 0x00;
    state.e = 0xd8;
    state.h = 0x01;
    state.l = 0x4d;
    state.pc = 0x0100;
    state.sp = 0xFFFE;
    *state.f = 0xB0;

    /* init semaphore for pauses */
    sem_init(&gameboy_sem, 0, 0);

    /* mark as inited */
    gameboy_inited = 1;

    return;
}