int main(int argc, const char *argv[]) {

	int count = 1024*1024;
    float *data1 = (float *)malloc(sizeof(float)*count);              // original data set given to device
    float *data2 = (float *)malloc(sizeof(float)*count);              // original data set given to device
    float *results = (float *)malloc(sizeof(float)*count);              // original data set given to device
    int correct;               // number of correct results returned

    int i = 0;
    for(i = 0; i < count; i++) {
		//data1[i] = rand() / (float)RAND_MAX;
		//data2[i] = rand() / (float)RAND_MAX;
		data1[i] = 1.1;
		data2[i] = 3.2;
	}

	call_kernel(data1,data2,count,"./simple_add.cl",results);

    correct = 0;
    for(i = 0; i < count; i++) {
        if(results[i] == sin(data1[i]+data2[i]))
            correct++;
		//printf("%f-----%f\n",results[i],data1[i]+data2[i]);
    }
    printf("'%d/%d' correct values!\n", correct, count);


	free(data1);
	free(data2);
	free(results);
    return 0;
}
Beispiel #2
0
void
init_arrays(double target_time)
{

    if (DEBUG) fprintf(stderr, "called init_arrays with target_time = %f \n",
            (target_time * 1e6));

#ifdef _ENABLE_CUDA_KERNEL_
    if (options.target == gpu || options.target == both) {
    /* Setting size of arrays for Dummy Compute */
    int N = options.device_array_size;

    /* Device Arrays for Dummy Compute */
    allocate_device_arrays(N);
    
    double time_elapsed = 0.0;
    double t1 = 0.0, t2 = 0.0;
    
    while (1) {
        t1 = MPI_Wtime();
        
        if (options.target == gpu || options.target == both) {
            cudaStreamCreate(&stream);
            call_kernel(A, d_x, d_y, N, &stream);
            
            cudaDeviceSynchronize();
            cudaStreamDestroy(stream);
        }

        t2 = MPI_Wtime();
        if ((t2-t1) < target_time)
        {  
            N += 32;

            /* Now allocate arrays of size N */
            allocate_device_arrays(N);
        }
        else {
            break;
        }
    }
    
    /* we reach here with desired N so save it and pass it to options */
    options.device_array_size = N;
    if (DEBUG) fprintf(stderr, "correct N = %d\n", N);
    }
#endif

}
Beispiel #3
0
int main(int argc, const char *argv[]) {

    float xlc0 = 0.0;
    float ylc0 = 0.0;
    float ql0 = 0.7;
    float rc0 = 0.1;
    float re0 = 1.0;
    float phi0 = 0.0;
    float lpar[] = {ylc0,xlc0,ql0,rc0,re0,phi0};

	int count = 1024*1024;
    float *xi1 = (float *)malloc(sizeof(float)*count);
    float *xi2 = (float *)malloc(sizeof(float)*count);
    float *alpha1 = (float *)malloc(sizeof(float)*count);
    float *alpha2 = (float *)malloc(sizeof(float)*count);
    int correct;

    int i = 0;
    for(i = 0; i < count; i++) {
		xi1[i] = rand() / (float)RAND_MAX;
		xi2[i] = rand() / (float)RAND_MAX;
	}


	call_kernel(xi1,xi2,count,lpar,alpha1,alpha2,"./play_with.cl");

    float *alpha1_c = (float *)malloc(sizeof(float)*count);
    float *alpha2_c = (float *)malloc(sizeof(float)*count);
    correct = 0;
    for(i = 0; i < count; i++) {
		lq_nie(xi1[i],xi2[i],lpar,&alpha1_c[i],&alpha2_c[i]);
		printf("%f-----%f||%f-----%f\n",alpha1[i],alpha1_c[i],alpha2[i],alpha2_c[i]);
    }

	free(xi1);
	free(xi2);
	free(alpha1);
	free(alpha2);
	free(alpha1_c);
	free(alpha2_c);
    return 0;
}
void
do_compute_gpu(double seconds)
{
    int i,j;
    double time_elapsed = 0.0, t1 = 0.0, t2 = 0.0;

    {
        t1 = MPI_Wtime();

        /* Execute Dummy Kernel on GPU if set by user */
        if (options.target == both || options.target == gpu) {
            {
                cudaStreamCreate(&stream);
                call_kernel(A, d_x, d_y, options.device_array_size, &stream);
            }
        }

        t2 = MPI_Wtime();
        time_elapsed += (t2-t1);
    }
}
void 
init_arrays(double target_time) 
{
    
    if (DEBUG) fprintf(stderr, "called init_arrays with target_time = %f \n", (target_time * 1e6));
    int i = 0, j = 0;
    
    a = (float **)malloc(DIM * sizeof(float *));
    
    for (i = 0; i < DIM; i++) {
        a[i] = (float *)malloc(DIM * sizeof(float));
    }
    
    x = (float *)malloc(DIM * sizeof(float));
    y = (float *)malloc(DIM * sizeof(float));

    for (i = 0; i < DIM; i++) {
        x[i] = y[i] = 1.0f;
        for (j = 0; j < DIM; j++) {
            a[i][j] = 2.0f;
        }
    }

#ifdef _ENABLE_CUDA_KERNEL_
    if (options.target == gpu || options.target == both) {
    /* Setting size of arrays for Dummy Compute */
    int N = options.device_array_size;

    /* Device Arrays for Dummy Compute */
    allocate_device_arrays(N);
    
    double time_elapsed = 0.0;
    double t1 = 0.0, t2 = 0.0;
    
    while (1) {
        t1 = MPI_Wtime();
        
        if (options.target == gpu || options.target == both) {
            cudaStreamCreate(&stream);
            call_kernel(A, d_x, d_y, N, &stream);
            
            cudaDeviceSynchronize();
            cudaStreamDestroy(stream);
        }

        t2 = MPI_Wtime();
        if ((t2-t1) < target_time)
        {  
            N += 32;

            /* First free the old arrays */
            free_device_arrays();

            /* Now allocate arrays of size N */
            allocate_device_arrays(N);
        }
        else {
            break;
        }
    }
    
    /* we reach here with desired N so save it and pass it to options */
    options.device_array_size = N;
    if (DEBUG) fprintf(stderr, "correct N = %d\n", N);
    }
#endif

}
Beispiel #6
0
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
	InitializeLib(ImageHandle, SystemTable);
	CallConstructors();

	EFI_STATUS Status;

	const char16_t* searchdir = u"\\EFI\\ChaiOS\\";
	if (Status = SetWorkingDirectory(searchdir))
		printf(u"Error setting working directory: %s\r\n", getError(Status));

	CHAIOS_BOOT_FILES* bootfile = nullptr;
	while (bootfile = iterateBootFiles(bootfile))
	{
		if (bootfile->loadLocation != nullptr)
			continue;		//Support in-memory images

		EFI_FILE* file = OpenFile(bootfile->fileName, "r");
		if (!file)
		{
			printf(u"Error: could not open %s: %s\r\n", bootfile->fileName, getError(getErrno()));
		}
		UINT64 fileSize = GetFileSize(file);
		VOID* bootfilebuf = kmalloc(fileSize+1);
		UINTN read = ReadFile(bootfilebuf, 1, fileSize, file);
		if (read < fileSize)
			printf(u"Read %d bytes, failed\r\n", read);
		else
			printf(u"Successfully read %d bytes\r\n", read);
		//Boot file is now loaded into memory
		CloseFile(file);
		bootfile->loadLocation = bootfilebuf;
		bootfile->fileSize = fileSize;
		if (bootfile->bootType == CHAIOS_BOOT_CONFIGURATION)
		{
			//We need to parse this now. INI format
			((char*)bootfilebuf)[fileSize] = '\0';
			ini_parse_string((const char*)bootfilebuf, &bootini_handler, nullptr);
		}
	}

	//size_t value = GetIntegerInput(u"Enter scrolling lines configuration: ");
	//set_scrolllines(value);

	UINT32 AutoMode = IterateGraphicsMode(&match_config_resoultion);
	EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* info; UINTN SizeOfInfo;
	if (AutoMode == UINT32_MAX)
	{
		if (!EFI_ERROR(GetGraphicsModeInfo(AutoMode, &info, &SizeOfInfo)))
		{
			IterateGraphicsMode(&print_graphics_mode);
			size_t value = GetIntegerInput(u"Enter boot graphics mode: ");
			SetGraphicsMode(value);
			AutoMode = value;
		}
	}
	else
	{
		SetGraphicsMode(AutoMode);
	}
	if (!EFI_ERROR(GetGraphicsModeInfo(AutoMode, &info, &SizeOfInfo)))
	{
		printf(u"Graphics mode %d: %dx%d\r\n", AutoMode, info->HorizontalResolution, info->VerticalResolution);
	}

	puts(u"ChaiOS 0.09 UEFI Loader\r\n");
	int majorver = SystemTable->Hdr.Revision / (1 << 16);
	int minorver = SystemTable->Hdr.Revision % (1 << 16);
	printf(u"Firmware Vendor: %s, version: %d (UEFI:%d.%d)\r\n", SystemTable->FirmwareVendor, SystemTable->FirmwareRevision, majorver, minorver);
	//Read ACPI configuration tables
	//startup_acpi(SystemTable);
	//startup_multiprocessor();

	const size_t EARLY_PAGE_STACK_SIZE = 1024*1024;
	EFI_PHYSICAL_ADDRESS earlyPhypageStack = 0;
	if (EFI_ERROR(SystemTable->BootServices->AllocatePages(AllocateAnyPages, EfiLoaderData, EARLY_PAGE_STACK_SIZE / EFI_PAGE_SIZE, &earlyPhypageStack)))
	{
		puts(u"Could not allocate page stack\r\n");
		return EFI_OUT_OF_RESOURCES;
	}

	SystemTable->BootServices->SetWatchdogTimer(0, 0, 0, nullptr);

	PrepareExitBootServices();

	EfiMemoryMap map;
	map.MemMapSize = map.MapKey = map.DescriptorSize = map.DescriptorVersion = 0;

	SystemTable->BootServices->GetMemoryMap(&map.MemMapSize, nullptr, &map.MapKey, &map.DescriptorSize, &map.DescriptorVersion);
	//Give a nice bit of room to spare (memory map can change)
	map.MemMapSize += 16 * map.DescriptorSize;
	map.memmap = (EFI_MEMORY_DESCRIPTOR*)kmalloc(map.MemMapSize);	//Allocate a nice buffer

	SystemTable->BootServices->GetMemoryMap(&map.MemMapSize, map.memmap, &map.MapKey, &map.DescriptorSize, &map.DescriptorVersion);
	printf(u"EFI Memory Map: Descriptor size %d\n", map.DescriptorSize);
#if 0
	//Dump the UEFI memory map to a file for testing
	EFI_FILE* file = OpenFile(u"efimap.dat", "w");
	if (!file)
	{
		printf(u"Error: could not open %s: %s\r\n", u"efimap.dat", getError(getErrno()));
	}
	WriteFile(map.memmap, 1, map.MemMapSize, file);
	CloseFile(file);
#endif
	if (EFI_ERROR(Status = SystemTable->BootServices->ExitBootServices(ImageHandle, map.MapKey)))
	{
		printf(u"Failed to exit boot services: %s\r\n", getError(Status));
		UINTN index;
		SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->WaitForKey, &index);
		return EFI_SUCCESS;
	}
	//We need to take control of the hardware now. Setup basic memory management
	setLiballocAllocator(nullptr, nullptr);

	InitializePmmngr(map, (void*)earlyPhypageStack, EARLY_PAGE_STACK_SIZE);
	puts(u"Physical memory manager intialized\n");
	arch_initialize_paging();
	puts(u"Paging initialized\n");
	setLiballocAllocator(&arch_allocate_pages, &arch_free_pages);
	//Now load the OS!
	bootfile = nullptr;
	kimage_entry kentry = nullptr;
	KLOAD_HANDLE kernel = NULL;
	while (bootfile = iterateBootFiles(bootfile))
	{
		printf(u"Boot file: %s @ %x, length %d, type %d\n", bootfile->fileName, bootfile->loadLocation, bootfile->fileSize, bootfile->bootType);
		if (!bootfile->loadLocation)
			continue;
		if (bootfile->bootType == CHAIOS_DLL)
		{
			KLOAD_HANDLE dll = LoadImage(bootfile->loadLocation, bootfile->fileName);
			if (GetProcAddress(dll, "memcpy"))
			{
				set_memcpy((memcpy_proc)GetProcAddress(dll, "memcpy"));
			}
		}
		else if (bootfile->bootType == CHAIOS_KERNEL)
		{
			kernel = LoadImage(bootfile->loadLocation, bootfile->fileName);
			kentry = GetEntryPoint(kernel);
		}
	}

	size_t kstacksize = GetStackSize(kernel);

	if (!paging_map(stackaddr, PADDR_T_MAX, kstacksize, PAGE_ATTRIBUTE_WRITABLE))
	{
		puts(u"Error: could not allocate kernel stack\n");
		while (1);
	}

	KERNEL_BOOT_INFO bootinfo;
	fill_pmmngr_info(bootinfo.pmmngr_info);
	fill_arch_paging_info(bootinfo.paging_info);
	fill_modloader_info(bootinfo.modloader_info);
	get_framebuffer_info(bootinfo.fbinfo);
	populate_kterm_info(bootinfo.kterm_status);
	bootinfo.efi_system_table = SystemTable;
	bootinfo.memory_map = &map;
	bootinfo.loaded_files = &bootfiles;
	bootinfo.boottype = CHAIOS_BOOT_TYPE_UEFI;
	bootinfo.printf_proc = &printf;
	bootinfo.puts_proc = &puts;

	printf(u"Success: Kernel entry point at %x, stack at %x, length %x\n", kentry, stackaddr, kstacksize);
	call_kernel(&bootinfo, kentry, stackaddr, kstacksize);
	puts(u"Kernel returned");
	while (1);
}