예제 #1
0
파일: Main.cpp 프로젝트: haibo031031/elmo
int main(int argc, char ** argv)
{
    float * h_raw, * h_out, * outCPU;
    cl_mem d_raw, d_out;
    try {
        if(argc!=2) {
            printf("need one parameter here!!!");
            exit(-1);
        }

        _clInit(1, "gpu", 0);


#if defined TIME
        double start_time = 0;
        double end_time = 0;
        string dat_name="data.dat";

        FILE * fp = fopen(dat_name.c_str(), "a+");
        if(fp==NULL)
        {
            printf("failed to open file!!!\n");
            exit(-1);
        }
#endif

        int cdim = atoi(argv[1]); //{384};
        int rdim = atoi(argv[1]); //{288};
        printf("cdim=%d, rdim=%d\n", cdim, rdim);
        h_raw = (float *)malloc(cdim * rdim * sizeof(float));
        h_out = (float *)malloc(cdim * rdim * sizeof(float));
        outCPU = (float *)malloc(cdim * rdim * sizeof(float));
        fill<float>(h_raw, cdim * rdim, 5);
        d_raw = _clMalloc(cdim * rdim * sizeof(float));
        d_out = _clMalloc(cdim * rdim * sizeof(float));
        _clMemcpyH2D(d_raw, h_raw, cdim * rdim * sizeof(float));
        printf("-0\n");
#ifdef VARIFY
        CPURun(h_raw, outCPU, cdim, rdim);
#endif //VARIFY

        /**************************1****************************/
#ifdef TIME
        start_time = gettime();
#endif
        printf("-1.1\n");
        broadcast(d_raw, d_out, cdim, rdim);
        printf("-1.2\n");
#ifdef TIME
        end_time = gettime();
        fprintf(fp, "%lf\t", (end_time - start_time));
#endif

#ifdef VARIFY
        _clMemcpyD2H(h_out, d_out, cdim * rdim * sizeof(float));
        verify_array<float>(outCPU, h_out, cdim * rdim);
#endif //VARIFY

        /**************************2****************************/
#ifdef TIME
        start_time = gettime();
#endif
        broadcast_lm(d_raw, d_out, cdim, rdim);
        printf("-2\n");
#ifdef TIME
        end_time = gettime();
        fprintf(fp, "%lf\t", (end_time - start_time));
#endif

#ifdef VARIFY
        _clMemcpyD2H(h_out, d_out, cdim * rdim * sizeof(float));
        verify_array<float>(outCPU, h_out, cdim * rdim);
#endif //VARIFY

#ifdef TIME
        fprintf(fp, "\n");
        fclose(fp);
#endif
    }
    catch(string msg) {
        printf("ERR:%s\n", msg.c_str());
        printf("Error catched\n");
    }
    _clFree(d_raw);
    _clFree(d_out);
    _clRelease();
    if(h_raw!=NULL) free(h_raw);
    if(h_out!=NULL) free(h_out);
    if(outCPU!=NULL) free(outCPU);

    return 1;
}
예제 #2
0
파일: Main.cpp 프로젝트: haibo031031/elmo
int main(int argc, char ** argv)
{
	uint * in = NULL, * out_cpu = NULL, * out_gpu = NULL;
	cl_mem d_in = NULL, d_out = NULL;
try{
	if(argc!=2){
		printf("need 1 parameter here!!!");
		exit(-1);
	}

	_clInit(1, "gpu", 0);
	uint iter = 100;
	
#if defined TIME
	double start_time = 0.0;
	double end_time = 0.0;
	double deltaT = 0.0;
	string dat_name="data.dat";

	FILE * fp = fopen(dat_name.c_str(), "a+");
	if(fp==NULL)
	{
		printf("failed to open file!!!\n");
		exit(-1);
	}
#endif
	
	// parameters
	uint side = atoi(argv[1]);
	uint wData = side;
	uint hData = side;
	uint size = wData * hData;

	printf("wData=%d, hData=%d\n", wData, hData);
	
	// allocate memory space on the host and device side
	in = (uint * )malloc(size * sizeof(uint));
	out_cpu = (uint * )malloc(size * sizeof(uint));
	out_gpu = (uint * )malloc(size * sizeof(uint));
	
	d_in = _clMalloc(size * sizeof(uint));	
	d_out = _clMalloc(size * sizeof(uint));

	// initialization
	fill<uint>(in, size, 16);

	// copy data from host to device
	_clMemcpyH2D(d_in, in, size * sizeof(uint));
	
	// warm-up
	mt_1(d_in, d_out, wData, hData);
	mt_2(d_in, d_out, wData, hData);
	mt_3(d_in, d_out, wData, hData);
	
#ifdef VARIFY	
	CPURun(in, out_cpu, wData, hData);
#endif //VARIFY
	
	/**************************1****************************/
#ifdef TIME
	deltaT = 0.0;
#endif
	for(int i=0; i<iter; i++)
	{
	
#ifdef TIME
	start_time = gettime();
#endif

		mt_1(d_in, d_out, wData, hData);
	
#ifdef TIME	
	end_time = gettime();
	deltaT += end_time - start_time;	
#endif
	}	
#ifdef TIME
	fprintf(fp, "%lf\t", deltaT/(double)iter);
#endif

#ifdef VARIFY
	_clMemcpyD2H(out_gpu, d_out, size * sizeof(uint));
	verify_array_int<uint>(out_cpu, out_gpu, size);
#endif //VARIFY

	/**************************2****************************/
#ifdef TIME
	deltaT = 0.0;
#endif
	for(int i=0; i<iter; i++)
	{
	
#ifdef TIME
	start_time = gettime();
#endif

		mt_2(d_in, d_out, wData, hData);
	
#ifdef TIME	
	end_time = gettime();
	deltaT += end_time - start_time;	
#endif
	}	
#ifdef TIME
	fprintf(fp, "%lf\t", deltaT/(double)iter);
#endif

#ifdef VARIFY
	_clMemcpyD2H(out_gpu, d_out, size * sizeof(uint));
	verify_array_int<uint>(out_cpu, out_gpu, size);
#endif //VARIFY

	/**************************3****************************/
#ifdef TIME
	deltaT = 0.0;
#endif
	for(int i=0; i<iter; i++)
	{
	
#ifdef TIME
	start_time = gettime();
#endif

		mt_3(d_in, d_out, wData, hData);
	
#ifdef TIME	
	end_time = gettime();
	deltaT += end_time - start_time;	
#endif
	}	
#ifdef TIME
	fprintf(fp, "%lf\t", deltaT/(double)iter);
#endif

#ifdef VARIFY
	_clMemcpyD2H(out_gpu, d_out, size * sizeof(uint));
	verify_array_int<uint>(out_cpu, out_gpu, size);
#endif //VARIFY

#ifdef TIME	
	fprintf(fp, "\n");	
	fclose(fp);
#endif	
}
catch(string msg){
	printf("ERR:%s\n", msg.c_str());
	printf("Error catched\n");
	}

	_clFree(d_in);
	_clFree(d_out);
	_clRelease();
	if(in!=NULL) free(in);
	if(out_cpu!=NULL) free(out_cpu);
	if(out_gpu!=NULL) free(out_gpu);

	return 1;
}
int main(int argc, char *argv[]) {
	//printf("working");

	if (argc == 9) {
		process_count = atoi(argv[2]);
		kproc_count = atoi(argv[4]);
		ioproc_count = atoi(argv[6]);
		pcproc_count = atoi(argv[8]);
		calcproc_count = process_count - (kproc_count + ioproc_count + (pcproc_count * 2));
	} else {
		process_count = 15;
		kproc_count = 3;
		ioproc_count = 3;
		pcproc_count = 3;
		calcproc_count = 3;
	}

	ReadyQPtr = QueueConstructor();

	int i;
	for (i = 0; i < kproc_count; i++) {
		PCBPtr a = PCBConstructor(processidcount, 2, 2, -1);
		enqueue(ReadyQPtr, a);
		processidcount++;
	}
	for (i = 0; i < pcproc_count; i++) {
		PCBPtr c = PCBConstructor(processidcount, 3, 2, i);
		enqueue(ReadyQPtr, c);
		processidcount++;
		PCBPtr d = PCBConstructor(processidcount, 4, 2, i);
		enqueue(ReadyQPtr, d);
		processidcount++;
	}
	for (i = 0; i < calcproc_count; i++) {
		PCBPtr e = PCBConstructor(processidcount, 0, 2, -1);
		enqueue(ReadyQPtr, e);
		processidcount++;
	}
	for (i = 0; i < ioproc_count; i++) {
		PCBPtr b = PCBConstructor(processidcount, 1, 2, -1);
		enqueue(ReadyQPtr, b);
		processidcount++;
	}
	for (i = 0; i < pcproc_count; i++) {
		sharedMemory[i] = 0;
	}
	//initialize interrupt flags
	IO1INT = 0;
	IO2INT = 0;
	KBINT = 0;
	TIMERINT = 0;
	KBHASPCB = 0;
	//printf("\nProcess Count %d", process_count);
	//printQueue(ReadyQPtr);
	//printf("\nProcess Count2");
	cpuPtr cpu = cpuConstructor();
	//printf("\nCPU Program Complete");

	CPURun(cpu);

	return 0;
}