mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Better alternating between video cards
This commit is contained in:
parent
ac82bde55f
commit
324e0a33dd
77
src/opencl.c
77
src/opencl.c
@ -2,6 +2,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
cl_info cl = {0};
|
cl_info cl = {0};
|
||||||
|
|
||||||
@ -12,22 +15,28 @@ void check_error(cl_info info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAX_DEVICES 10
|
||||||
|
|
||||||
cl_info cl_init()
|
cl_info cl_init()
|
||||||
{
|
{
|
||||||
cl_info info;
|
cl_info info;
|
||||||
info.initialized = 0;
|
info.initialized = 0;
|
||||||
//cl_uint num_platforms, num_devices;
|
cl_uint num_platforms, num_devices;
|
||||||
// Fetch the Platform and Device IDs; we only want one.
|
// Fetch the Platform and Device IDs; we only want one.
|
||||||
cl_device_id devices[2];
|
cl_device_id devices[MAX_DEVICES];
|
||||||
info.error=clGetPlatformIDs(1, &info.platform, 0);
|
info.error=clGetPlatformIDs(1, &info.platform, &num_platforms);
|
||||||
check_error(info);
|
check_error(info);
|
||||||
info.error=clGetDeviceIDs(info.platform, CL_DEVICE_TYPE_ALL, 2, devices, 0);
|
info.error=clGetDeviceIDs(info.platform, CL_DEVICE_TYPE_ALL, MAX_DEVICES, devices, &num_devices);
|
||||||
info.device = devices[rand()%2];
|
if(num_devices > MAX_DEVICES) num_devices = MAX_DEVICES;
|
||||||
|
int index = getpid()%num_devices;
|
||||||
|
printf("%d rand, %d devices, %d index\n", getpid(), num_devices, index);
|
||||||
|
info.device = devices[index];
|
||||||
|
fprintf(stderr, "Found %d device(s)\n", num_devices);
|
||||||
check_error(info);
|
check_error(info);
|
||||||
|
|
||||||
cl_context_properties properties[]={
|
cl_context_properties properties[]={
|
||||||
CL_CONTEXT_PLATFORM, (cl_context_properties)info.platform,
|
CL_CONTEXT_PLATFORM, (cl_context_properties)info.platform,
|
||||||
0};
|
0};
|
||||||
// Note that nVidia's OpenCL requires the platform property
|
// Note that nVidia's OpenCL requires the platform property
|
||||||
info.context=clCreateContext(properties, 1, &info.device, 0, 0, &info.error);
|
info.context=clCreateContext(properties, 1, &info.device, 0, 0, &info.error);
|
||||||
check_error(info);
|
check_error(info);
|
||||||
@ -39,41 +48,41 @@ cl_info cl_init()
|
|||||||
|
|
||||||
cl_program cl_fprog(char *filename, char *options, cl_info info)
|
cl_program cl_fprog(char *filename, char *options, cl_info info)
|
||||||
{
|
{
|
||||||
size_t srcsize;
|
size_t srcsize;
|
||||||
char src[8192];
|
char src[8192];
|
||||||
memset(src, 0, 8192);
|
memset(src, 0, 8192);
|
||||||
FILE *fil=fopen(filename,"r");
|
FILE *fil=fopen(filename,"r");
|
||||||
srcsize=fread(src, sizeof src, 1, fil);
|
srcsize=fread(src, sizeof src, 1, fil);
|
||||||
fclose(fil);
|
fclose(fil);
|
||||||
const char *srcptr[]={src};
|
const char *srcptr[]={src};
|
||||||
// Submit the source code of the example kernel to OpenCL
|
// Submit the source code of the example kernel to OpenCL
|
||||||
cl_program prog=clCreateProgramWithSource(info.context,1, srcptr, &srcsize, &info.error);
|
cl_program prog=clCreateProgramWithSource(info.context,1, srcptr, &srcsize, &info.error);
|
||||||
check_error(info);
|
check_error(info);
|
||||||
char build_c[4096];
|
char build_c[4096];
|
||||||
// and compile it (after this we could extract the compiled version)
|
// and compile it (after this we could extract the compiled version)
|
||||||
info.error=clBuildProgram(prog, 0, 0, options, 0, 0);
|
info.error=clBuildProgram(prog, 0, 0, options, 0, 0);
|
||||||
if ( info.error != CL_SUCCESS ) {
|
if ( info.error != CL_SUCCESS ) {
|
||||||
fprintf(stderr, "Error Building Program: %d\n", info.error);
|
fprintf(stderr, "Error Building Program: %d\n", info.error);
|
||||||
clGetProgramBuildInfo( prog, info.device, CL_PROGRAM_BUILD_LOG, 4096, build_c, 0);
|
clGetProgramBuildInfo( prog, info.device, CL_PROGRAM_BUILD_LOG, 4096, build_c, 0);
|
||||||
fprintf(stderr, "Build Log for %s program:\n%s\n", filename, build_c);
|
fprintf(stderr, "Build Log for %s program:\n%s\n", filename, build_c);
|
||||||
}
|
}
|
||||||
return prog;
|
return prog;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cl_setup()
|
void cl_setup()
|
||||||
{
|
{
|
||||||
if(!cl.initialized){
|
if(!cl.initialized){
|
||||||
cl = cl_init();
|
cl = cl_init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_kernel get_kernel(char *filename, char *kernelname, char *options)
|
cl_kernel get_kernel(char *filename, char *kernelname, char *options)
|
||||||
{
|
{
|
||||||
cl_setup();
|
cl_setup();
|
||||||
cl_program prog = cl_fprog(filename, options, cl);
|
cl_program prog = cl_fprog(filename, options, cl);
|
||||||
cl_kernel kernel=clCreateKernel(prog, kernelname, &cl.error);
|
cl_kernel kernel=clCreateKernel(prog, kernelname, &cl.error);
|
||||||
check_error(cl);
|
check_error(cl);
|
||||||
return kernel;
|
return kernel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -672,8 +672,6 @@ void features_VOC_image(char *image_file, char *image_dir, char *out_dir, int fl
|
|||||||
if (flip)sprintf(out_path, "%s%d/%s_r.txt",out_dir, interval, image_file);
|
if (flip)sprintf(out_path, "%s%d/%s_r.txt",out_dir, interval, image_file);
|
||||||
else sprintf(out_path, "%s%d/%s.txt",out_dir, interval, image_file);
|
else sprintf(out_path, "%s%d/%s.txt",out_dir, interval, image_file);
|
||||||
printf("%s\n", image_file);
|
printf("%s\n", image_file);
|
||||||
FILE *fp = fopen(out_path, "w");
|
|
||||||
if(fp == 0) file_error(out_path);
|
|
||||||
|
|
||||||
IplImage* src = 0;
|
IplImage* src = 0;
|
||||||
if( (src = cvLoadImage(image_path,-1)) == 0 ) file_error(image_path);
|
if( (src = cvLoadImage(image_path,-1)) == 0 ) file_error(image_path);
|
||||||
@ -709,6 +707,8 @@ void features_VOC_image(char *image_file, char *image_dir, char *out_dir, int fl
|
|||||||
ims[j+interval] = features_output_size(net, src, ex_h, ex_w);
|
ims[j+interval] = features_output_size(net, src, ex_h, ex_w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
FILE *fp = fopen(out_path, "w");
|
||||||
|
if(fp == 0) file_error(out_path);
|
||||||
for(i = 0; i < max_scale+interval; ++i){
|
for(i = 0; i < max_scale+interval; ++i){
|
||||||
image out = ims[i];
|
image out = ims[i];
|
||||||
fprintf(fp, "%d, %d, %d\n",out.c, out.h, out.w);
|
fprintf(fp, "%d, %d, %d\n",out.c, out.h, out.w);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user