Beispiel #1
0
//This function uses ALTERA SDK for OpenCL
cl_program
ocl_create_program_from_binary_for_fpga(OclPlatform *ocl, const char* binaryfile)
{
        cl_program temp;
        temp = createProgramFromBinary(ocl->context, binaryfile, ocl->devices, (unsigned int) ocl->num_devices);
        return temp;

}
Beispiel #2
0
	// Initializes the OpenCL objects.
	bool init_opencl(const int maxInputSize, const int maxOutputSize, const int maxWeightSize, const int maxBiasSize) {
		cl_int status;

		if (!setCwdToExeDir()) {
			return false;
		}

		// Get the OpenCL platform.
		platform = findPlatform("Altera");
		if (platform == NULL) {
			printf("ERROR: Unable to find Altera OpenCL platform.\n");
			return false;
		}

		printf("Platform: %s\n", getPlatformName(platform).c_str());

		// Query the available OpenCL devices.
		scoped_array<cl_device_id> devices;
		cl_uint num_devices;

		devices.reset(getDevices(platform, CL_DEVICE_TYPE_ALL, &num_devices));

		// We'll just use the first device.
		device = devices[0];
		printf("Device: %s\n", getDeviceName(device).c_str());

		// Create the context.
		context = clCreateContext(NULL, 1, &device, &oclContextCallback, NULL, &status);
		checkError(status, "Failed to create context");

		// Create the command queue.
		queue = clCreateCommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE, &status);
		checkError(status, "Failed to create command queue");

		// Create the program.
		std::string binary_file = getBoardBinaryFile("waifu2x", device);
		printf("Using AOCX: %s\n", binary_file.c_str());
		program = createProgramFromBinary(context, binary_file.c_str(), &device, 1);

		// Build the program that was just created.
		status = clBuildProgram(program, 0, NULL, "", NULL, NULL);
		checkError(status, "Failed to build program");

		// Create the kernel - name passed in here must match kernel name in the
		// original CL file, that was compiled into an AOCX file using the AOC tool
		const char *kernel_name = "waifu2x";  // Kernel name, as defined in the CL file
		kernel = clCreateKernel(program, kernel_name, &status);
		checkError(status, "Failed to create kernel");

		input_buf = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_BANK_1_ALTERA,
			maxInputSize * sizeof(float), NULL, &status);
		checkError(status, "Failed to create buffer for input");

		weight_buf = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_BANK_2_ALTERA,
			maxWeightSize * sizeof(float), NULL, &status);
		checkError(status, "Failed to create buffer for weight");

		bias_buf = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_BANK_2_ALTERA,
			maxBiasSize * sizeof(double), NULL, &status);
		checkError(status, "Failed to create buffer for bias");

		output_buf = clCreateBuffer(context, CL_MEM_WRITE_ONLY | CL_MEM_BANK_1_ALTERA,
			maxOutputSize * sizeof(float), NULL, &status);
		checkError(status, "Failed to create buffer for output");

		return true;
	}