コード例 #1
0
ファイル: HelloWorld.c プロジェクト: ilangal-amd/CLOC
int main(int argc, char* argv[]) {
	char* input = "Gdkkn\x1FGR@\x1FVnqkc";
	size_t strlength = strlen(input);
	char *output = (char*) malloc_global(strlength + 1);
	char *secode = (char*) malloc_global(strlength + 1);
	char *output2 = (char*) malloc_global(strlength + 1);

        SNK_INIT_LPARM(lparm,strlength);
        decode(input,output,lparm);
	output[strlength] = '\0';
	printf("Decoded       :%s\n",output);
        /* Show we can call multiple functions in the .cl file */
        super_encode(output,secode,lparm);
        printf("Super encoded :%s\n",secode);
        super_decode(secode,output2,lparm);
        printf("Super decoded :%s\n",output2);
       /* Show we can call same function multiple times */
        decode(secode,output,lparm);
        decode(output,output2,lparm);
	printf("Decoded twice :%s\n",output2);
	free(output);
	free(secode);
	free(output2);
	return 0;
}
コード例 #2
0
ファイル: blur.c プロジェクト: BryantChang/HSA-Bench
int main(int argc, char **argv) {
	if(argc < 2) {
		usage();
		return -1;
	}

	//init the filter array
	float filter[49] =
      {1,      1,      1,      1,      1,      1,      1,
       1,      1,      1,      1,      1,      1,      1,
       1,      1,      1,      1,      1,      1,      1,
       1,      1,      1,      1,      1,      1,      1,
       1,      1,      1,      1,      1,      1,      1,
       1,      1,      1,      1,      1,      1,      1,
       1,      1,      1,      1,      1,      1,      1};

	//operate the params of cmd
	const char* inputFileName; 
    const char* outputFileName; 
    inputFileName = (argv[1]);
    outputFileName = (argv[2]);

    //the image height and width
    int imageHeight, imageWidth;
    
    //read the bmp image to the memory
    float* inputImage = readBmpImage(inputFileName, &imageWidth, &imageHeight);

    //to check the read is succ
    printf("the width of the image is %d, the height of the image is %d\n", imageWidth, imageHeight);

    //calculate the datasize
    int dataSize = imageHeight * imageWidth * sizeof(float);

    //output image
    float *outputImage = NULL;
    outputImage = (float*)malloc(dataSize);

    //init lparm
    SNK_INIT_LPARM(lparm, (imageWidth * imageHeight));
    lparm->ndim=2; 
    lparm->gdims[0]=imageWidth;
    lparm->gdims[1]=imageHeight;
    lparm->ldims[0]=1;
    lparm->ldims[1]=1;
    
    //call the blur function
    int filterWidth = 7;
    blur(outputImage, inputImage, imageWidth, imageHeight, filter, filterWidth, lparm);

    //store the image 
    storeBmpImage(outputImage, outputFileName, imageHeight, imageWidth, inputFileName);
    free(outputImage);
	return 0;
}
コード例 #3
0
ファイル: rotation.c プロジェクト: BryantChang/HSA-Bench
int main(int argc, char **argv) {
	if(argc < 2) {
		usage();
		return -1;
	}
	//operate the params of cmd
	const char* inputFileName; 
    const char* outputFileName; 
    inputFileName = (argv[1]);
    outputFileName = (argv[2]);
    printf("1233556\n");
	//calculate the sin(theta) & cos(theta)
	float sinTheta = sinf(THETA);
	float cosTheta = cosf(THETA);

    //the image height and width
    int imageHeight, imageWidth;
    

    //read the bmp image to the memory
    float* inputImage = readBmpImage(inputFileName, &imageWidth, &imageHeight);

    //to check the read is succ
    printf("the width of the image is %d, the height of the image is %d\n", imageWidth, imageHeight);

    //calculate the datasize
    int dataSize = imageHeight * imageWidth * sizeof(float);

    //output image
    float *outputImage = NULL;
    outputImage = (float*)malloc(dataSize);

    //init lparm
    SNK_INIT_LPARM(lparm, (imageWidth * imageHeight));
    lparm->ndim=2; 
    lparm->gdims[0]=imageWidth;
    lparm->gdims[1]=imageHeight;
    lparm->ldims[0]=1;
    lparm->ldims[1]=1;
    
    //call the rotate function
    image_rotate(outputImage,inputImage,imageWidth,imageHeight,sinTheta,cosTheta,lparm);

    //store the image 
    storeBmpImage(outputImage, outputFileName, imageHeight, imageWidth, inputFileName);
    free(outputImage);


	return 0;
}
コード例 #4
0
ファイル: cl_version.c プロジェクト: weichen8157/HSA_kmeans
// ------------------------------------
// 更新table, 傳回sse, 存入點之變動數
float update_table_cl(int* ch_pt)
{
    int i, j, k, min_k;
    float dis,  t_sse=0.0;
    float data_ker[DCNT*DIM];
    float cent_ker[K*DIM];
    int cent_c_ker[DCNT];
    //float min_dis;
    int chpt[DCNT];
    float min_dis[DCNT];
    unsigned int k_ker=K,dim_ker=DIM,dcnt_ker=DCNT;

    *ch_pt=0;                          // 變動點數設0
    memset(cent_c, 0, sizeof(cent_c)); // 各叢聚資料數清0
    memset(dis_k, 0, sizeof(dis_k));   // 各叢聚距離和清0
    /*OpenCL*/
    size_t work_size;

    for (i=0; i<DCNT;++i) {
        for(k=0; k<DIM;++k) {
            data_ker[i*DIM+k]=data[i][k];
        }
    }
    for (i=0; i<K;++i) {
        for(k=0; k<DIM;++k) {
            cent_ker[i*DIM+k]=cent[i][k];
        }
    }

    //err = 0;
   
    /*snack
    err |= clEnqueueWriteBuffer(queue, cl_data, CL_TRUE, 0, 
                                sizeof(float) * DCNT * DIM, data_ker, 0, 0, 0);
    err |= clEnqueueWriteBuffer(queue, cl_cent, CL_TRUE, 0, 
                                sizeof(float) * K * DIM, cent_ker, 0, 0, 0);
    err |= clEnqueueWriteBuffer(queue, cl_table, CL_TRUE, 0, 
                                sizeof(int) * DCNT, table, 0, 0, 0);

    err |= clSetKernelArg(kernel, 3, sizeof(unsigned int), &k_ker);
    err |= clSetKernelArg(kernel, 4, sizeof(unsigned int), &dim_ker);
    err |= clSetKernelArg(kernel, 5, sizeof(unsigned int), &dcnt_ker);

    err |= clEnqueueWriteBuffer(queue, cl_chpt, CL_TRUE, 0, 
                                sizeof(int) * DCNT, chpt, 0, 0, 0);
    err |= clEnqueueWriteBuffer(queue, cl_cent_c, CL_TRUE, 0, 
                                sizeof(int) * DCNT, cent_c_ker, 0, 0, 0);
    err |= clEnqueueWriteBuffer(queue, cl_min_dis, CL_TRUE, 0, 
                                sizeof(float) * DCNT, min_dis, 0, 0, 0);
    if (err) {
        printf("ERROR! WRITE BUFFER\n");
        exit(1);
    }

    work_size = DCNT;
    err = clEnqueueNDRangeKernel(queue, kernel, 1, 0, &work_size, 0, 0, 0, 0);

    if (err == CL_SUCCESS) {
        err |= clEnqueueReadBuffer(queue, cl_chpt, CL_TRUE, 0, sizeof(cl_int)*DCNT, &chpt[0], 0, 0, 0);
        err |= clEnqueueReadBuffer(queue, cl_table, CL_TRUE, 0, sizeof(cl_int)*DCNT, &table[0], 0, 0, 0);
        err |= clEnqueueReadBuffer(queue, cl_cent_c, CL_TRUE, 0, sizeof(cl_int)*DCNT, &cent_c_ker[0], 0, 0, 0);
        err |= clEnqueueReadBuffer(queue, cl_min_dis, CL_TRUE, 0, sizeof(cl_float)*DCNT, &min_dis[0], 0, 0, 0);
    }
    */
    
    /*
    float * data_ker=(float*)malloc(DCNT*DIM);
    float * cent_ker=(float*)malloc(K*DIM);
    int * table=(int*)malloc(DCNT);
    unsigned int * k_ker=(unsigned int*)malloc(K);
    unsigned int * dim_ker=(unsigned int*)malloc(DIM);
    unsigned int * dcnt_ker=(unsigned int*)malloc(DCNT);
    int * chpt=(int*)malloc(DCNT);
    int * cent_c_ker=(int*)malloc(DCNT);
    float * min_dis=(float*)malloc(DCNT);
*/  
    //our snack code
    SNK_INIT_LPARM(lparm,DCNT); 
   cal_diskernel(data_ker,cent_ker,table,K,DIM,DCNT,chpt,cent_c_ker,min_dis,lparm); 

    for(i=0;i<DCNT;i++) {
        *ch_pt+=chpt[i];
        ++cent_c[cent_c_ker[i]];
        t_sse+=min_dis[i];
        for(j=0;j<DIM;j++) {
            dis_k[table[i]][j]+=data[i][j];
        }
    }

    return t_sse;
}
コード例 #5
0
ファイル: VectorCopy.cpp プロジェクト: GreenFLOPS-HSA/bench
int main(int argc, char **argv)
{
    struct timeval tstart, tstop;
    unsigned long int meas[NB_MEASURE];
    unsigned long int meas2[NB_MEASURE];
    unsigned long int duration = 0;
    unsigned long int var = 0;
    unsigned int size = 1;
    int verbose = 0;
    int i = 0;
    int c;
    int prefillingcache = 0;
    int coef = 1;
    int nbopt = 0;
int flops = 0;

    while ((c = getopt(argc, argv, "cf")) != -1)
	switch (c) {
	case 'c':
	    prefillingcache = 1;
	    nbopt++;
	    break;
	case 'f':
	flops = 1;
	nbopt++;
	break;
	default:
	    abort();
	}

    if (2 <= argc) {
	int pos = nbopt + 1;

	if (NULL != strcasestr(argv[pos], "kB"))
	    coef = 1024;
	else if (NULL != strcasestr(argv[pos], "MB"))
	    coef = 1024 * 1024;
	else if (NULL != strcasestr(argv[pos], "GB"))
	    coef = 1024 * 1024 * 1024;

	size *= coef * atoi(argv[pos]);
    }
    if (1 == coef) {
	size *= sizeof(float);
    }
    //Setup kernel arguments
    float *in = (float *) malloc(size);
    float *out = (float *) malloc(size);
    memset(out, 0, size);
    memset(in, 0, size);
    for (i = 0; i < (size / sizeof(float)); i++)
	in[i] = i;

    // Mesure NBR_COPY copy vector
    //gettimeofday(&tstart, NULL);
    //for (int i = 0; i < LOOPS; i++) {
    SNK_INIT_LPARM(lparm, size / sizeof(float));
    //Fill Caches
    if (prefillingcache) {
	printf("Pre-filling cache option SET\n");
	for (i = 0; i < 64; i++) {
		if(flops) flops_3(in, out, lparm)
		else vcopy(in, out, lparm);
	}
    }

    for (i = 0; i < NB_MEASURE; i++) {
	gettimeofday(&tstart, NULL);
	vcopy(in, out, lparm);
	gettimeofday(&tstop, NULL);
	meas[i] =
	    ((tstop.tv_sec - tstart.tv_sec) * 1000000L + tstop.tv_usec) -
	    tstart.tv_usec;
	//meas2[i] = meas[i] * meas[i];
    }
    for (i = 0; i < NB_MEASURE; i++) {
	duration += meas[i];
	//var += meas2[i];
    }
    duration /= NB_MEASURE;
    for (i = 0; i < NB_MEASURE; i++) {
	var += ((meas[i] - duration) * (meas[i] - duration));
    }
    var /= NB_MEASURE;
    //var -= duration * duration;

	if(flops){
	printf
                ("HSA: Vector of %lu integer of %d-bytes = %lu Bytes takes %lu usec [+/-var %lu] => Speed = %.3f\n",
                (size / sizeof(float)), (int) sizeof(float), size, duration, var, (float)(3.0 * size/sizeof(float) / duration * 1000000));
	}
	else{
    	printf
		("HSA: Vector of %lu integer of %d-bytes = %lu Bytes takes %lu usec [+/-var %lu]\n",
	 	(size / sizeof(float)), (int) sizeof(float), size, duration, var);
	}
    //Validate
    bool valid = true;
    int failIndex = 0;
    for (i = 0; i < (size / sizeof(float)); i++) {
	if (verbose && i < 10)
	    printf("in[%d]=%d, out[%d]=%d, ", i, in[i], i, out[i]);
	if (out[i] != in[i]) {
	    failIndex = i;
	    valid = false;
	    break;
	}
    }
    if (valid) {
	if (verbose)
	    printf("passed validation\n");
    } else
	printf("VALIDATION FAILED!\nBad index: %d\n", failIndex);
    free(in);
    free(out);
    return 0;
}