コード例 #1
0
ファイル: memmem.c プロジェクト: havardh/bitless
int main(void) 
{
	
	CHIP_Init();

	if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  BSP_Init(BSP_INIT_DEFAULT);
	BSP_LedsSet(0);

  BSP_PeripheralAccess(BSP_AUDIO_IN, true);
  BSP_PeripheralAccess(BSP_AUDIO_OUT, true);

  RTCDRV_Trigger(1000, NULL);
  EMU_EnterEM2(true);

  initSource();

	setupCMU();
  setupDMA();
  
  //setupADC();
  //setupDAC();

  //setupDMAInput();
  //setupDMAOutput();

	//setupDMASplit();
	//setupDMAMerge();

  ADCConfig();
  DACConfig();

  TIMER_Init_TypeDef timerInit = TIMER_INIT_DEFAULT;
  TIMER_TopSet(TIMER0, CMU_ClockFreqGet(cmuClock_HFPER) / SAMPLE_RATE);
  TIMER_Init(TIMER0, &timerInit);

	Delay(100);
	BSP_LedsSet(3);
	Delay(500);
	BSP_LedsSet(0);
	Delay(100);

	while(1) {
		volatile bool result = test();
		if (result) {
			BSP_LedsSet(0x00FF);
		} else {
			BSP_LedsSet(0xFF00);			
		}
		Delay(1000);
    BSP_LedsSet(0x0);    
    Delay(1000);
	}

}
コード例 #2
0
ファイル: Problem.cpp プロジェクト: Yukariko/cocos2d-x
void Problem::setInit()
{
	sourceY = 0;
	memX = 0;
	memY = 0;
	smSwitch = false;
	pushShift = false;
	pushEnter = false;
	myInput = NULL;
	setSource();
	initSource();
	initMemory();
}
コード例 #3
0
ファイル: compile.c プロジェクト: kzfm1024/misc
int compile()
{
	int i;
	printf("start compilation\n");
	initSource();				/* getSourceの初期設定 */
	token = nextToken();			/* 最初のトークン */
	blockBegin(FIRSTADDR);		/* これ以後の宣言は新しいブロックのもの */
	block(0);					/* 0 はダミー(主ブロックの関数名はない) */
	finalSource();
	i = errorN();				/* エラーメッセージの個数 */
	if (i!=0)
		printf("%d errors\n", i);
/*	listCode();	*/			/* 目的コードのリスト(必要なら) */
	return i<MINERROR;		/* エラーメッセージの個数が少ないかどうかの判定 */
}
コード例 #4
0
void OpenALMusicPlayer::start()
{
	if (!ready) {
		if (stream->getSoundFormat() == SoundStream::FORMAT_INVALID) {
			GfError("OpenALMusicPlayer: Sound stream has invalid format\n");
			return;
		}
		
		if (initContext() && initBuffers() && initSource()) {
			ready = true;
			startPlayback();
		}
		
		return;
	}
}
コード例 #5
0
ファイル: video.cpp プロジェクト: hackorama/tag-video
bool 
Video::initVideo()
{

	d_videofile = NULL;
	initVideoParams();
	bool result = false;
	result = initDShow();
	if(result)  result = initFrameFilter();
	if(result)  result = initSource();
	if(result) VIDEO_STATUS = 0;
	if(result && d_graphedit ) { 
		hr = d_addGraphToRot(graph, &d_graphRegister);
		if(FAILED(hr)) d_graphRegister = NULL;	
	}
	
	return startVideo();
}
コード例 #6
0
ファイル: SoundSource.cpp プロジェクト: drwbns/1stperson
void SoundSource::activate(bool activate)
{
	if (activate == mActive)
		return;

	if (activate)
	{
		float position = mTimer->getPosition();
		while(position > mBuffer->getDuration())
			position -= mBuffer->getDuration();

		initSource();
		if (mState == AL_PLAYING)
			play();
		seek(position);
	}
	else
	{
		//mSecOffset = mTimer.getPosition();
		deinitSource();
	}
}
コード例 #7
0
/*
 * Source - main driver
 */
vi_rc Source( char *fn, char *data, int *ln )
{
    undo_stack  *atomic = NULL;
    labels      *lab, lb;
    vlist       vl;
    files       fi;
    sfile       *sf, *curr;
    char        tmp[MAX_SRC_LINE];
    char        sname[FILENAME_MAX];
    vi_rc       rc;
    bool        sicmp, wfb, ssa, exm;
    resident    *res;
    int         cTokenID;

    /*
     * startup
     */
    LastRC = LastRetCode;
    memset( &fi, 0, sizeof( fi ) );
    vl.head = vl.tail = NULL;
    res = residentScript( fn );
    if( res != NULL && EditFlags.LoadResidentScript ) {
        return( ERR_SCRIPT_ALREADY_RESIDENT );
    }
    if( EditFlags.CompileScript || res == NULL ) {
        lab = &lb;
        memset( lab, 0, sizeof( labels ) );
        sf = NULL;
    } else {
        lab = &res->lab;
        sf = res->sf;
    }
    if( EditFlags.CompileScript ) {
        sname[0] = 0;
        NextWord1( data, sname );
    }

    /*
     * initialize variables
     */
    memset( &fi, 0, sizeof( fi ) );
    rc = initSource( &vl, data );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }

    /*
     * pre-process
     */
    sicmp = EditFlags.ScriptIsCompiled;
    SourceErrCount = 0;
    if( EditFlags.CompileScript || res == NULL ) {
        EditFlags.ScriptIsCompiled = FALSE;
        rc = PreProcess( fn, &sf, lab );
        finiSourceErrFile( fn );
        if( rc != ERR_NO_ERR || SourceErrCount > 0 ) {
            EditFlags.ScriptIsCompiled = sicmp;
            return( rc );
        }
    } else {
        EditFlags.ScriptIsCompiled = res->scriptcomp;
    }

    /*
     * if we were loading a resident script, then add it
     */
    if( EditFlags.LoadResidentScript ) {
        finiSource( NULL, &vl, NULL, NULL );
        if( SourceErrCount == 0 ) {
            addResidentScript( fn, sf, lab );
        }
        EditFlags.ScriptIsCompiled = sicmp;
        return( ERR_NO_ERR );
    }

    /*
     * if we were compiling, dump results and go back
     */
    if( EditFlags.CompileScript ) {
        rc = barfScript( fn, sf, &vl, ln, sname );
        finiSource( lab, &vl, sf, NULL );
        return( rc );
    }

    /*
     * process each source line
     */
    exm = EditFlags.ExMode;
    wfb = EditFlags.WatchForBreak;
    ssa = EditFlags.SourceScriptActive;
    EditFlags.SourceScriptActive = TRUE;
    EditFlags.WatchForBreak = TRUE;
    EditFlags.ExMode = TRUE;
    curr = sf->next;
    while( curr != NULL ) {

        cTokenID = curr->token - SRC_T_NULL - 1;

        if( !EditFlags.Starting ) {
            if( EditFlags.BreakPressed ) {
                ClearBreak();
                break;
            }
        }
        rc = LastError = ERR_NO_ERR;
        if( curr->data != NULL ) {
            strcpy( tmp, curr->data );
        } else {
            tmp[0] = 0;
        }

        if( EditFlags.Appending ) {
            if( curr->hasvar) {
                Expand( tmp, &vl );
            }
            rc = AppendAnother( tmp );
            goto evil_continue;
        }

        if( cTokenID == PCL_T_ENDFILETYPESOURCE ) {
            rc = FTSEnd();
            goto evil_continue;
        }

        if( EditFlags.FileTypeSource ) {
            rc = FTSAddCmd( tmp, curr->token );
            goto evil_continue;
        }

        if( curr->token > SRC_T_NULL ) {

            if( curr->hasvar) {
                Expand( tmp, &vl );
            }
            rc = TryCompileableToken( cTokenID, tmp, FALSE, 0 );
            if( rc == NOT_COMPILEABLE_TOKEN ) {
                rc = ProcessWindow( cTokenID, tmp );
            }
            if( rc < ERR_NO_ERR ) {
                rc = ERR_NO_ERR;
            }

        } else switch( curr->token ) {
        case SRC_T_ATOMIC:
            if( atomic == NULL ) {
                atomic = UndoStack;
                StartUndoGroup( atomic );
            }
            break;

        case SRC_T_IF:
            rc = SrcIf( &curr, &vl );
            break;

        case SRC_T_GOTO:
            rc = SrcGoTo( &curr, tmp, lab );
            break;

        case SRC_T_LABEL:
            break;

        case SRC_T_RETURN:
            if( curr->data != NULL ) {
                int     ret;
                GetErrorTokenValue( &ret, curr->data );
                rc = ret;
            } else {
                rc = ERR_NO_ERR;
            }
            goto evil_exit;

        case SRC_T_GET:
            SrcGet( tmp, &vl );
            rc = ERR_NO_ERR;
            break;

        case SRC_T_INPUT:
            LastRC = SrcInput( tmp, &vl );
            if( LastRC != NO_VALUE_ENTERED && LastRC != ERR_NO_ERR ) {
                rc = LastRC;
            }
            break;

        case SRC_T_NEXTWORD:
            rc = SrcNextWord( tmp, &vl );
            break;

        case SRC_T_ASSIGN:
            rc = SrcAssign( tmp, &vl );
            break;

        case SRC_T_EXPR:
            rc = SrcExpr( curr, &vl );
            break;

        case SRC_T_OPEN:
            LastRC = SrcOpen( curr, &vl, &fi, tmp );
            if( LastRC != ERR_FILE_NOT_FOUND && LastRC != ERR_NO_ERR ) {
                rc = LastRC;
            }
            break;

        case SRC_T_READ:
            LastRC = SrcRead( curr, &fi, tmp, &vl );
            if( LastRC != END_OF_FILE && LastRC != ERR_NO_ERR ) {
                rc = LastRC;
            }
            break;

        case SRC_T_WRITE:
            rc = SrcWrite( curr, &fi, tmp, &vl );
            break;

        case SRC_T_CLOSE:
            rc = SrcClose( curr, &vl, &fi, tmp );
            break;

        default:
#ifdef __WIN__
            {
                if( RunWindowsCommand( tmp, &LastRC, &vl ) ) {
                    rc = LastRC;
                    break;
                }
            }
#endif
            if( curr->hasvar ) {
                Expand( tmp, &vl );
            }
            LastRC = RunCommandLine( tmp );
            if( LastRC == DO_NOT_CLEAR_MESSAGE_WINDOW ) {
                LastRC = LastError;
            }
            break;
        }

evil_continue:
        if( rc != ERR_NO_ERR ) {
            break;
        }
        curr = curr->next;

    }

evil_exit:
    if( EditFlags.Appending ) {
        AppendAnother( "." );
    }
    if( curr != NULL ) {
        *ln = curr->line;
    } else {
        *ln = CurrentSrcLine;
        rc = ERR_NO_ERR;
    }
    EditFlags.WatchForBreak = wfb;
    EditFlags.SourceScriptActive = ssa;
    EditFlags.ScriptIsCompiled = sicmp;
    EditFlags.ExMode = exm;
    if( res != NULL && !EditFlags.CompileScript ) {
        sf = NULL;
        lab = NULL;
    }
    finiSource( lab, &vl, sf, atomic );
    return( rc );

} /* Source */
コード例 #8
0
ファイル: 10_mpi.cpp プロジェクト: candycode/opencl-training
//------------------------------------------------------------------------------
int main(int argc, char** argv) {
    if(argc < 5) {
        std::cout << "usage: " << argv[0]
                << " <platform id(0, 1, ...)>"
                   " <device type: default | cpu | gpu | acc>"
                   " <device id(0, 1, ...)>"
                   " <number of double prec. elements>\n";

        exit(EXIT_FAILURE);          
    }
    std::vector<cl::Platform> platforms;
    std::vector<cl::Device> devices;
    const int platformID = atoi(argv[1]);
    cl_device_type deviceType;
    const std::string kernelName(argv[4]);
    const std::string dt = std::string(argv[2]);
    if(dt == "default") deviceType = CL_DEVICE_TYPE_DEFAULT;
    else if(dt == "cpu") deviceType = CL_DEVICE_TYPE_CPU;
    else if(dt == "gpu") deviceType = CL_DEVICE_TYPE_GPU;
    else if(dt == "acc") deviceType = CL_DEVICE_TYPE_ACCELERATOR;
    else {
      std::cerr << "ERROR - unrecognized device type " << dt << std::endl;
      exit(EXIT_FAILURE);
    } 
    const int deviceID = atoi(argv[3]);
    const size_t SIZE = atoll(argv[4]);
    const size_t BYTE_SIZE = SIZE * sizeof(real_t);
    // init MPI environment
    MPI_Init(&argc, &argv);
    int task = -1;
   
    MPI_Comm_rank(MPI_COMM_WORLD, &task);
    try {
       
        //OpenCL init
        cl::Platform::get(&platforms);
        if(platforms.size() <= platformID) {
            std::cerr << "Platform id " << platformID << " is not available\n";
            exit(EXIT_FAILURE);
        }
   
        platforms[platformID].getDevices(deviceType, &devices);
        cl::Context context(devices);
        cl::CommandQueue queue(context, devices[deviceID],
                               CL_QUEUE_PROFILING_ENABLE);

        std::vector< real_t > data(SIZE, -1);
        //device buffer #1: holds local data
        cl::Buffer devData(context,
                            CL_MEM_READ_WRITE 
                            | CL_MEM_ALLOC_HOST_PTR //<-- page locked memory
                            | CL_MEM_COPY_HOST_PTR, //<-- copy data from 'data'
                            BYTE_SIZE,
                            const_cast< double* >(&data[0]));
        //device buffer #2: holds data received from other node
        cl::Buffer devRecvData(context,
                            CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
                            BYTE_SIZE);
        //process data on the GPU(set array elements to local MPI id)  
        const char CLCODE_INIT[] =
            "#pragma OPENCL EXTENSION cl_khr_fp64: enable\n"
            "typedef double real_t;\n"
            "__kernel void arrayset(__global real_t* outputArray,\n"
            "                       real_t value) {\n"
            "//get global thread id for dimension 0\n"
            "const int id = get_global_id(0);\n"
            "outputArray[id] = value;\n" 
            "}";
    
        cl::Program::Sources initSource(1, 
                                        std::make_pair(CLCODE_INIT,
                                                       sizeof(CLCODE_INIT)));
        cl::Program initProgram(context, initSource);
        initProgram.build(devices);
        cl::Kernel initKernel(initProgram, "arrayset");        
        initKernel.setArg(0, devData);
        initKernel.setArg(1, real_t(task));
       
        queue.enqueueNDRangeKernel(initKernel,
                                 cl::NDRange(0),
                                 cl::NDRange(SIZE),
                                 cl::NDRange(1));

        //perform data exchange:
        //1) map device buffers to host memory
        void* sendHostPtr = queue.enqueueMapBuffer(devData,
                                               CL_FALSE,
                                               CL_MAP_READ,
                                               0,
                                               BYTE_SIZE);

        if(sendHostPtr == 0) throw std::runtime_error("NULL mapped ptr");
    
        void* recvHostPtr = queue.enqueueMapBuffer(devRecvData,
                                               CL_FALSE,
                                               CL_MAP_WRITE,
                                               0,
                                               BYTE_SIZE);
       
        if(recvHostPtr == 0) throw std::runtime_error("NULL mapped ptr");

        queue.finish();

        //2) copy data to from remote process
        const int tag0to1 = 0x01;
        const int tag1to0 = 0x10;
        MPI_Request send_req;
        MPI_Request recv_req;
        int source = -1;
        int dest = -1;
        if(task == 0 ) {
            source = 1;
            dest   = 1;
        } else {
            source = 0;
            dest   = 0;
        }

        MPI_Status status;
        if(task == 0) {
            MPI_Isend(sendHostPtr, SIZE, MPI_DOUBLE, dest,
                      tag0to1, MPI_COMM_WORLD, &send_req);
            MPI_Irecv(recvHostPtr, SIZE, MPI_DOUBLE, source,
                      tag1to0, MPI_COMM_WORLD, &recv_req);
        } else {
            MPI_Isend(sendHostPtr, SIZE, MPI_DOUBLE, dest,
                      tag1to0, MPI_COMM_WORLD, &send_req);
            MPI_Irecv(recvHostPtr, SIZE, MPI_DOUBLE, source,
                      tag0to1, MPI_COMM_WORLD, &recv_req);
        }
        //3) as soon as data is copied do unmap buffers, indirectlry
        //   triggering a host --> device copy
        MPI_Wait(&recv_req, &status);
        queue.enqueueUnmapMemObject(devRecvData, recvHostPtr);
        MPI_Wait(&send_req, &status);
        queue.enqueueUnmapMemObject(devData, sendHostPtr);

        //note that instead of having each process compile the code
        //you could e.g. send the size and content of the source buffer
        //to each process from root; or even send the precompiled code,
        //in this case all nodes of the clusted must be the same whereas
        //in the case of source code compilation hybrid systems are
        //automatically supported by OpenCL

        //process data on the GPU: increment local data array with value
        //received from other process
        const char CLCODE_COMPUTE[] =
            "#pragma OPENCL EXTENSION cl_khr_fp64: enable\n"
            "typedef double real_t;\n"
            "__kernel void sum( __global const real_t* in,\n"
            "                   __global real_t* inout) {\n"
            "const int id = get_global_id(0);\n"
            "inout[id] += in[id];\n" 
            "}";
        cl::Program::Sources computeSource(1,
                                           std::make_pair(CLCODE_COMPUTE,
                                                          sizeof(CLCODE_COMPUTE)));
        cl::Program computeProgram(context, computeSource);
        computeProgram.build(devices);
        cl::Kernel computeKernel(computeProgram, "sum");        
        computeKernel.setArg(0, devRecvData);
        computeKernel.setArg(1, devData);

        queue.enqueueNDRangeKernel(computeKernel,
                                 cl::NDRange(0),
                                 cl::NDRange(SIZE),
                                 cl::NDRange(1));
        
        //map device data to host memory for validation and output
        real_t* computedDataHPtr = reinterpret_cast< real_t* >(
                                        queue.enqueueMapBuffer(devData,
                                               CL_FALSE,
                                               CL_MAP_READ,
                                               0,
                                               BYTE_SIZE));
        if(computedDataHPtr == 0) throw std::runtime_error("NULL mapped ptr");

        queue.finish();

        const int value = 1; // task id 0 + task id 1
        const std::vector< real_t > reference(SIZE, value);
        if(std::equal(computedDataHPtr, computedDataHPtr + SIZE,
                      reference.begin())) {
            std::cout << '[' << task << "]: PASSED" << std::endl;
        } else {
            std::cout << '[' << task << "]: FAILED" << std::endl;
        }
        //release mapped pointer
        queue.enqueueUnmapMemObject(devData, computedDataHPtr);
        //release MPI resources
        MPI_Finalize();
    } catch(cl::Error e) {
      std::cerr << e.what() << ": Error code " << e.err() << std::endl;
      MPI_Finalize();
      exit(EXIT_FAILURE);   
    }   
    return 0;
}