You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							76 lines
						
					
					
						
							1.8 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							76 lines
						
					
					
						
							1.8 KiB
						
					
					
				
								// Primitives.cpp : Defines the entry point for the console application.
							 | 
						|
								
							 | 
						|
								#include <string>
							 | 
						|
								#include <vector>
							 | 
						|
								#include <iostream>
							 | 
						|
								#include "Common.h"
							 | 
						|
								#include "OpenCLHandler.h"
							 | 
						|
								#include "primitives/Tests.h"
							 | 
						|
								
							 | 
						|
								// OpenCL C API
							 | 
						|
								#include <CL/opencl.h>
							 | 
						|
								
							 | 
						|
								// OpenCL C++ API
							 | 
						|
								#include "cl.hpp"
							 | 
						|
								
							 | 
						|
								//const size_t dataSize = 4096;
							 | 
						|
								//
							 | 
						|
								void capi()
							 | 
						|
								{
							 | 
						|
									// Get a platform ID
							 | 
						|
									cl_platform_id platformID;
							 | 
						|
									clGetPlatformIDs(1, &platformID, NULL);
							 | 
						|
									
							 | 
						|
									// Get a device ID
							 | 
						|
									cl_device_id deviceID;
							 | 
						|
									clGetDeviceIDs(platformID, CL_DEVICE_TYPE_GPU, 1, &deviceID, NULL);
							 | 
						|
									
							 | 
						|
									// Create a context
							 | 
						|
									cl_context context;
							 | 
						|
									cl_context_properties contextProperties[] =
							 | 
						|
									{ CL_CONTEXT_PLATFORM, (cl_context_properties)platformID, 0 };
							 | 
						|
									context = clCreateContext(contextProperties, 1, &deviceID, NULL, NULL, NULL);
							 | 
						|
									
							 | 
						|
									// Create a command queue
							 | 
						|
									cl_command_queue queue;
							 | 
						|
									queue = clCreateCommandQueue(context, deviceID, CL_QUEUE_PROFILING_ENABLE, NULL);
							 | 
						|
									
							 | 
						|
									// Create an OpenCL program
							 | 
						|
									std::string source = FileToString("../kernels/programs.cl");
							 | 
						|
									const char* csource = source.c_str();
							 | 
						|
									cl_program program = clCreateProgramWithSource(context, 1, &csource, NULL, NULL);
							 | 
						|
									cl_int err = clBuildProgram(program, 1, &deviceID, NULL, NULL, NULL);
							 | 
						|
									if (err != CL_SUCCESS)
							 | 
						|
									{
							 | 
						|
										cl_uint logLength;
							 | 
						|
										clGetProgramBuildInfo(program, deviceID, CL_PROGRAM_BUILD_LOG, 0, NULL, &logLength);
							 | 
						|
										char* log = new char[logLength];
							 | 
						|
										clGetProgramBuildInfo(program, deviceID, CL_PROGRAM_BUILD_LOG, logLength, log, 0);
							 | 
						|
										std::cout << log << std::endl;
							 | 
						|
										delete[] log;
							 | 
						|
										exit(-1);
							 | 
						|
									}
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								int main()
							 | 
						|
								{
							 | 
						|
									capi();
							 | 
						|
									OpenCLHandler handler;
							 | 
						|
									std::vector<TestCase*> tests;
							 | 
						|
								
							 | 
						|
									Square s;
							 | 
						|
									Histogram h(false, 32, 4096);
							 | 
						|
									ReduceAdd r1(handler.get_max_size());
							 | 
						|
								
							 | 
						|
									//handler.run_test(&s);
							 | 
						|
									//handler.run_test(&h);
							 | 
						|
									if (handler.run_test(&r1)) {
							 | 
						|
										std::cout << "Success" << std::endl;
							 | 
						|
									}
							 | 
						|
									else {
							 | 
						|
										std::cout << "Failure" << std::endl;
							 | 
						|
									}
							 | 
						|
								    return 0;
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								
							 |