Exemplo n.º 1
0
int main() {

    float* vector;
    float value;
    int i,found;
    /* SimpleOpenCL types declaration */
    sclHard* hardware;
    sclSoft software;

    /* NDRange 2D size initialization*/
    size_t global_size[2];
    size_t local_size[2];
    size_t dataLength=134217728;
    size_t dataSize=sizeof(float)*dataLength;

    global_size[0]=dataLength;
    global_size[1]=1;
    local_size[0]=1;
    local_size[1]=1;
    /*local_size[0]=1 might be necessary for CPU devices on apple machines*/


    /* Data generation */
    vector = (float*)malloc(dataSize);
    value = 3;
    for (i=0; i<(int)dataLength; i++) {
        vector[i] = (float)i;
    }

    /* Hardware and Software initialization ##### HERE STARTS THE SimpleOpenCL CODE ####*/
    found=0;
    hardware = sclGetAllHardware(&found);
    software = sclGetCLSoftware("example2.cl","example2",hardware[DEVICE]);

    /* Kernel execution */
    sclManageArgsLaunchKernel( hardware[DEVICE], software,
                               global_size, local_size,
                               "%R %a %N",
                               dataSize, (void*)vector, sizeof(float), (void*)&value, sizeof(float));

    /* Data is read back from the device automatically  ##### HERE ENDS THE SimpleOpenCL CODE ####*/
    /* We print some values to check the results */

    printf("\nExecution successful\n");
    printf("vector[0]=%f vector[10]=%f vector[200]=%f\n",vector[0],vector[10],vector[200]);

    return 0;

}
Exemplo n.º 2
0
int main(){
	
sclHard* allHardware;
sclHard hardware;
sclSoft software;

matrix ma;
ma.cols = 4;
ma.rows = 4;
ma.dataSize = sizeof(int);
ma.dataStart = calloc(ma.cols*ma.rows, ma.dataSize);

for (int i = 0; i < ma.rows; ++i)
{
	for (int j = 0; j < ma.cols; ++j)
	{
		((int*)ma.dataStart)[i*ma.cols+j] = j;
	}
}

printMatrix(ma);
/*
int a[] = {1,2,3,4,5,6,7,8,9};
int b[] = {9,8,7,6,5,4,3,2,1};
int result[9];

size_t global_size[2];
size_t local_size[2];
size_t dataLength = 9;
size_t dataSize = sizeof(int)*dataLength;

global_size[0] = dataLength;
local_size[0] = 1;
global_size[1] = 1;
local_size[1] = 1;*/

size_t global_size[2];
size_t local_size[2];
size_t dataLength = ma.cols*ma.rows;
size_t dataSize = ma.dataSize*dataLength;

global_size[0] = dataLength;
local_size[0] = 4;
global_size[1] = 1;
local_size[1] = 1;
int scalar = 2;

int found = 0;
allHardware = sclGetAllHardware(&found);
hardware = sclGetFastestDevice(allHardware, found);
software = sclGetCLSoftware("Noget.cl", "Noget2", hardware);

/*sclManageArgsLaunchKernel(hardware, software, global_size, local_size, "%R %R %R", 
	dataSize, a, dataSize, b, dataSize, result);
*/
sclManageArgsLaunchKernel(hardware, software, global_size, local_size, "%R %a", 
	dataSize, ma.dataStart, sizeof(int) ,&scalar);
printf("\n");

printMatrix(ma);

}