void WebResourceCacheManager::clearCacheForOrigin(SecurityOriginData originData, uint32_t cachesToClear) const { WebProcess::LocalTerminationDisabler terminationDisabler(WebProcess::shared()); #if USE(CFURLCACHE) ResourceCachesToClear resourceCachesToClear = static_cast<ResourceCachesToClear>(cachesToClear); #else UNUSED_PARAM(cachesToClear); #endif RefPtr<SecurityOrigin> origin = SecurityOrigin::create(originData.protocol, originData.host, originData.port); if (!origin) return; memoryCache()->removeResourcesWithOrigin(origin.get()); #if USE(CFURLCACHE) if (resourceCachesToClear != InMemoryResourceCachesOnly) { RetainPtr<CFMutableArrayRef> hostArray(AdoptCF, CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks)); CFArrayAppendValue(hostArray.get(), origin->host().createCFString().get()); clearCFURLCacheForHostNames(hostArray.get()); } #endif }
//------------------------------------------------------------------------------ int main(int argc, char** argv) { if(argc < 6) { std::cerr << "usage: " << argv[0] << " <platform name> <device type = default | cpu | gpu " "| acc | all> <device num> <OpenCL source file path>" " <kernel name>" << std::endl; exit(EXIT_FAILURE); } std::string platformName = argv[ 1 ]; std::string deviceType = argv[2]; int deviceNum = atoi(argv[3]); log_thread_count("\n\nstart"); #ifdef _OPENMP { // const int CHUNKSIZE = 100; // const int N = 1000; // int i, chunk; // float a[N], b[N], c[N]; // for (i=0; i < N; i++) // a[i] = b[i] = i * 1.0; // chunk = CHUNKSIZE; // printf("%d", omp_get_max_threads()); #pragma omp parallel //shared(a,b,c,chunk) private(i) { if(omp_get_thread_num() == 0) { log_thread_count("OMP PARALLEL"); } // printf("%d", omp_get_max_threads()); // #pragma omp for schedule(dynamic,chunk) nowait // for (i=0; i < N; i++) { // c[i] = a[i] + b[i]; // } } #pragma omp barrier } #endif //1)create context cl_context ctx = create_cl_context(platformName, deviceType, deviceNum); std::cout << "OpenCL context created" << std::endl; log_thread_count("CL context created"); //2)load kernel source const std::string programSource = load_text(argv[4]); std::cout << "OpenCL source code loaded" << std::endl; const char* src = programSource.c_str(); const size_t sourceLength = programSource.length(); //3)build program and create kernel cl_int status; cl_program program = clCreateProgramWithSource(ctx, //context 1, //number of strings &src, //source &sourceLength, // size &status); // status check_cl_error(status, "clCreateProgramWithSource"); cl_device_id deviceID; //only a single device was selected // retrieve actual device id from context status = clGetContextInfo(ctx, CL_CONTEXT_DEVICES, sizeof(cl_device_id), &deviceID, 0); check_cl_error(status, "clGetContextInfo"); cl_int buildStatus = clBuildProgram(program, //program 1, //number of devices &deviceID, //array of device ids 0, //program options as passed on //the command line to regualar //compilers e.g. -DUSE_DOUBLE 0, 0); //log output if any char buffer[0x10000] = ""; size_t len = 0; status = clGetProgramBuildInfo(program, deviceID, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len); check_cl_error(status, "clBuildProgramInfo"); if(len > 1) std::cout << "Build output: " << buffer << std::endl; check_cl_error(buildStatus, "clBuildProgram"); std::cout << "Built OpenCL program" << std::endl; const char* kernelName = argv[5]; cl_kernel kernel = clCreateKernel(program, kernelName, &status); check_cl_error(status, "clCreateKernel"); //4)allocate output buffer on OpenCL device typedef float real_t; const size_t ARRAY_LENGTH = 16; const size_t ARRAY_BYTE_LENGTH = ARRAY_LENGTH * sizeof(real_t); cl_mem outputCLBuffer = clCreateBuffer(ctx, CL_MEM_WRITE_ONLY, ARRAY_BYTE_LENGTH, 0, &status); check_cl_error(status, "clCreateBuffer"); //5)create command queue cl_command_queue commands = clCreateCommandQueue(ctx, deviceID, 0, &status); check_cl_error(status, "clCreateCommandQueue"); //6)set kernel parameters const real_t value = real_t(3.14); //first parameter: output array status = clSetKernelArg(kernel, //kernel 0, //parameter id sizeof(cl_mem), //size of parameter &outputCLBuffer); //pointer to parameter check_cl_error(status, "clSetKernelArg(0)"); //second parameter: value to assign to each array element status = clSetKernelArg(kernel, //kernel 1, //parameter id sizeof(real_t), //size of parameter &value); //pointer to parameter check_cl_error(status, "clSetKernelArg(1)"); //7)setup kernel launch configuration //total number of threads == number of array elements const size_t globalWorkSize[1] = {ARRAY_LENGTH}; //number of per-workgroup local threads const size_t localWorkSize[1] = {1}; //8)launch kernel status = clEnqueueNDRangeKernel(commands, //queue kernel, //kernel 1, //number of dimensions for work-items 0, //global work offset globalWorkSize, //total number of threads localWorkSize, //threads per workgroup 0, //number of events that need to //complete before kernel executed 0, //list of events that need to complete //before kernel executed 0); //event object identifying this //particular kernel execution instance check_cl_error(status, "clEnqueueNDRangeKernel"); log_thread_count("kernel launched"); std::cout << "Lunched OpenCL kernel - setting all array elements to " << value << std::endl; //9)read back and print results std::vector< real_t > hostArray(ARRAY_LENGTH, real_t(0)); status = clEnqueueReadBuffer(commands, outputCLBuffer, CL_TRUE, //blocking read 0, //offset ARRAY_BYTE_LENGTH, //byte size of data &hostArray[0], //destination buffer in host // memory 0, //number of events that need to //complete before transfer executed 0, //list of events that need to complete //before transfer executed 0); //event identifying this specific operation check_cl_error(status, "clEnqueueReadBuffer"); log_thread_count("device -> host transfer"); std::cout << "Output array: " << std::endl; std::ostream_iterator<real_t> out_it(std::cout, " "); std::copy(hostArray.begin(), hostArray.end(), out_it); std::cout << std::endl; //10)release resources check_cl_error(clReleaseMemObject(outputCLBuffer), "clReleaseMemObject"); check_cl_error(clReleaseCommandQueue(commands),"clReleaseCommandQueue"); check_cl_error(clReleaseKernel(kernel), "clReleaseKernel"); check_cl_error(clReleaseProgram(program), "clReleaseProgram"); check_cl_error(clReleaseContext(ctx), "clReleaseContext"); std::cout << "Released OpenCL resources" << std::endl; log_thread_count("released resources"); print_thread_count(threadlog.begin(), threadlog.end()); std::cout << std::endl; return 0; }