remove caching

pull/2744/head
deanlee 5 years ago
parent 94c395af58
commit f2e861413a
  1. 4
      selfdrive/camerad/cameras/camera_common.cc
  2. 2
      selfdrive/camerad/cameras/camera_qcom.cc
  3. 1
      selfdrive/camerad/main.cc
  4. 2
      selfdrive/camerad/transforms/rgb_to_yuv.c
  5. 1
      selfdrive/camerad/transforms/rgb_to_yuv_test.cc
  6. 127
      selfdrive/common/clutil.cc
  7. 11
      selfdrive/common/clutil.h
  8. 2
      selfdrive/modeld/transforms/loadyuv.c
  9. 2
      selfdrive/modeld/transforms/transform.cc

@ -41,9 +41,9 @@ static cl_program build_debayer_program(cl_device_id device_id, cl_context conte
b->rgb_width, b->rgb_height, b->rgb_stride,
ci->bayer_flip, ci->hdr);
#ifdef QCOM2
return CLU_LOAD_FROM_FILE(context, device_id, "cameras/real_debayer.cl", args);
return cl_program_from_file(context, device_id, "cameras/real_debayer.cl", args);
#else
return CLU_LOAD_FROM_FILE(context, device_id, "cameras/debayer.cl", args);
return cl_program_from_file(context, device_id, "cameras/debayer.cl", args);
#endif
}

@ -248,7 +248,7 @@ cl_program build_conv_program(cl_device_id device_id, cl_context context, int im
"-DFILTER_SIZE=%d -DHALF_FILTER_SIZE=%d -DTWICE_HALF_FILTER_SIZE=%d -DHALF_FILTER_SIZE_IMAGE_W=%d",
image_w, image_h, 1,
filter_size, filter_size/2, (filter_size/2)*2, (filter_size/2)*image_w);
return CLU_LOAD_FROM_FILE(context, device_id, "imgproc/conv.cl", args);
return cl_program_from_file(context, device_id, "imgproc/conv.cl", args);
}
void cameras_init(MultiCameraState *s, cl_device_id device_id, cl_context ctx) {

@ -330,7 +330,6 @@ int main(int argc, char *argv[]) {
signal(SIGINT, (sighandler_t)set_do_exit);
signal(SIGTERM, (sighandler_t)set_do_exit);
clu_init();
cl_device_id device_id = cl_get_device_id(CL_DEVICE_TYPE_DEFAULT);
cl_context context = CL_CHECK_ERR(clCreateContext(NULL, 1, &device_id, NULL, NULL, &err));

@ -20,7 +20,7 @@ void rgb_to_yuv_init(RGBToYUVState* s, cl_context ctx, cl_device_id device_id, i
#endif
"-DWIDTH=%d -DHEIGHT=%d -DUV_WIDTH=%d -DUV_HEIGHT=%d -DRGB_STRIDE=%d -DRGB_SIZE=%d",
width, height, width/ 2, height / 2, rgb_stride, width * height);
cl_program prg = CLU_LOAD_FROM_FILE(ctx, device_id, "transforms/rgb_to_yuv.cl", args);
cl_program prg = cl_program_from_file(ctx, device_id, "transforms/rgb_to_yuv.cl", args);
s->rgb_to_yuv_krnl = CL_CHECK_ERR(clCreateKernel(prg, "rgb_to_yuv", &err));
// done with this

@ -101,7 +101,6 @@ bool compare_results(uint8_t *a, uint8_t *b, int len, int stride, int width, int
int main(int argc, char** argv) {
srand(1337);
clu_init();
cl_device_id device_id;
cl_context context;
cl_init(device_id, context) ;

@ -1,23 +1,14 @@
#include "clutil.h"
#include <assert.h>
#include <string.h>
#include <inttypes.h>
#include <string.h>
#include <sys/stat.h>
#include <memory>
#include <vector>
#include "common/util.h"
#include "util.h"
#include "utilpp.h"
#include "clutil.h"
#ifdef CLU_NO_SRC
#include "clcache_bins.h"
#else
#endif
void clu_init(void) {
#ifndef CLU_NO_SRC
mkdir("/tmp/clcache", 0777);
#endif
}
namespace { // helper functions
namespace { // helper functions
std::string get_platform_info(cl_platform_id platform, cl_platform_info param_name) {
size_t size = 0;
@ -27,6 +18,7 @@ std::string get_platform_info(cl_platform_id platform, cl_platform_info param_na
CL_CHECK(clGetPlatformInfo(platform, param_name, size, &ret[0], NULL));
return ret;
}
void cl_print_info(cl_platform_id platform, cl_device_id device) {
std::string info = get_platform_info(platform, CL_PLATFORM_VENDOR);
printf("vendor: '%s'\n", info.c_str());
@ -47,33 +39,33 @@ void cl_print_info(cl_platform_id platform, cl_device_id device) {
clGetDeviceInfo(device, CL_DEVICE_VERSION, sizeof(str), str, NULL);
printf("device version: '%s'\n", str);
size_t sz;
size_t sz = 0;
clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(sz), &sz, NULL);
printf("max work group size: %zu\n", sz);
cl_device_type type;
cl_device_type type = 0;
clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(type), &type, NULL);
printf("type = 0x%04x = ", (unsigned int)type);
switch(type) {
case CL_DEVICE_TYPE_CPU:
printf("CL_DEVICE_TYPE_CPU\n");
break;
case CL_DEVICE_TYPE_GPU:
printf("CL_DEVICE_TYPE_GPU\n");
break;
case CL_DEVICE_TYPE_ACCELERATOR:
printf("CL_DEVICE_TYPE_ACCELERATOR\n");
break;
default:
printf("Other...\n" );
break;
switch (type) {
case CL_DEVICE_TYPE_CPU:
printf("CL_DEVICE_TYPE_CPU\n");
break;
case CL_DEVICE_TYPE_GPU:
printf("CL_DEVICE_TYPE_GPU\n");
break;
case CL_DEVICE_TYPE_ACCELERATOR:
printf("CL_DEVICE_TYPE_ACCELERATOR\n");
break;
default:
printf("Other...\n");
break;
}
}
void cl_print_build_errors(cl_program program, cl_device_id device) {
cl_build_status status;
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_STATUS,
sizeof(cl_build_status), &status, NULL);
sizeof(cl_build_status), &status, NULL);
size_t log_size;
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
@ -83,45 +75,6 @@ void cl_print_build_errors(cl_program program, cl_device_id device) {
printf("build failed; status=%d, log:\n%s\n", status, &log[0]);
}
#ifndef CLU_NO_CACHE
cl_program load_cached_program(cl_context ctx, cl_device_id device_id, std::string cache_file) {
size_t bin_size;
uint8_t* bin = (uint8_t*)read_file(cache_file.c_str(), &bin_size);
if (!bin) return NULL;
cl_program prg = CL_CHECK_ERR(clCreateProgramWithBinary(ctx, 1, &device_id, &bin_size, (const uint8_t**)&bin, NULL, &err));
free(bin);
CL_CHECK(clBuildProgram(prg, 1, &device_id, NULL, NULL, NULL));
return prg;
}
std::vector<uint8_t> get_program_binary(cl_program prg) {
cl_uint num_devices = 0;
CL_CHECK(clGetProgramInfo(prg, CL_PROGRAM_NUM_DEVICES, sizeof(num_devices), &num_devices, NULL));
assert(num_devices == 1);
size_t binary_size = 0;
CL_CHECK(clGetProgramInfo(prg, CL_PROGRAM_BINARY_SIZES, sizeof(binary_size), &binary_size, NULL));
assert(binary_size > 0);
std::vector<uint8_t> binary_buf(binary_size);
uint8_t* bufs[] = {&binary_buf[0]};
CL_CHECK(clGetProgramInfo(prg, CL_PROGRAM_BINARIES, sizeof(bufs), &bufs, NULL));
return binary_buf;
}
std::string get_cached_path(cl_device_id device_id, const char* src, const char* args,
const char* file, int line, const char* function) {
cl_platform_id platform;
CL_CHECK(clGetDeviceInfo(device_id, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL));
std::string platform_version = get_platform_info(platform, CL_PLATFORM_VERSION);
std::string hash_buf = util::string_format("%s%s%d%s%s", platform_version.c_str(), file, line, function, src, args);
const size_t hash = std::hash<std::string>{}(hash_buf);
return util::string_format("/tmp/clcache/%016" PRIx64 ".clb", hash);
}
#endif
} // namespace
cl_device_id cl_get_device_id(cl_device_type device_type) {
@ -145,43 +98,23 @@ cl_device_id cl_get_device_id(cl_device_type device_type) {
cl_print_info(platform_ids[i], device_id);
return device_id;
}
printf("No valid openCL platform found\n");
assert(0);
return nullptr;
}
cl_program cl_program_from_string(cl_context ctx, cl_device_id device_id, const char* src, const char* args,
const char* file, int line, const char* function) {
cl_program prg = NULL;
#ifndef CLU_NO_CACHE
std::string cache_path = get_cached_path(device_id, src, args, file, line, function);
prg = load_cached_program(ctx, device_id, cache_path);
#endif
if (prg == NULL) {
prg = CL_CHECK_ERR(clCreateProgramWithSource(ctx, 1, (const char**)&src, NULL, &err));
int err = clBuildProgram(prg, 1, &device_id, args, NULL, NULL);
if (err != 0) {
cl_print_build_errors(prg, device_id);
}
assert(err == 0);
#ifndef CLU_NO_CACHE
// write program binary to cache
std::vector<uint8_t> binary_buf = get_program_binary(prg);
write_file(cache_path.c_str(), binary_buf.data(), binary_buf.size());
#endif
cl_program cl_program_from_file(cl_context ctx, cl_device_id device_id, const char* path, const char* args) {
char* src = (char*)read_file(path, nullptr);
assert(src != nullptr);
cl_program prg = CL_CHECK_ERR(clCreateProgramWithSource(ctx, 1, (const char**)&src, NULL, &err));
free(src);
if (int err = clBuildProgram(prg, 1, &device_id, args, NULL, NULL); err != 0) {
cl_print_build_errors(prg, device_id);
assert(0);
}
return prg;
}
cl_program cl_program_from_file(cl_context ctx, cl_device_id device_id, const char* path, const char* args,
const char* file, int line, const char* function) {
std::string src_buf = util::read_file(path);
return cl_program_from_string(ctx, device_id, &src_buf[0], args, file, line, function);
}
// Given a cl code and return a string represenation
const char* cl_get_error_string(int err) {
switch (err) {

@ -27,19 +27,10 @@ extern "C" {
_ret; \
})
void clu_init(void);
cl_device_id cl_get_device_id(cl_device_type device_type);
cl_program cl_program_from_string(cl_context ctx, cl_device_id device_id, const char* src, const char* args,
const char* file, int line, const char* function);
cl_program cl_program_from_file(cl_context ctx, cl_device_id device_id, const char* path, const char* args,
const char* file, int line, const char* function);
cl_program cl_program_from_file(cl_context ctx, cl_device_id device_id, const char* path, const char* args);
const char* cl_get_error_string(int err);
#define CLU_LOAD_FROM_STRING(ctx, device_id, src, args) \
cl_program_from_string(ctx, device_id, src, args, __FILE__, __LINE__, __func__);
#define CLU_LOAD_FROM_FILE(ctx, device_id, path, args) \
cl_program_from_file(ctx, device_id, path, args, __FILE__, __LINE__, __func__);
#ifdef __cplusplus
}
#endif

@ -16,7 +16,7 @@ void loadyuv_init(LoadYUVState* s, cl_context ctx, cl_device_id device_id, int w
"-cl-fast-relaxed-math -cl-denorms-are-zero "
"-DTRANSFORMED_WIDTH=%d -DTRANSFORMED_HEIGHT=%d",
width, height);
cl_program prg = CLU_LOAD_FROM_FILE(ctx, device_id, "transforms/loadyuv.cl", args);
cl_program prg = cl_program_from_file(ctx, device_id, "transforms/loadyuv.cl", args);
s->loadys_krnl = CL_CHECK_ERR(clCreateKernel(prg, "loadys", &err));
s->loaduv_krnl = CL_CHECK_ERR(clCreateKernel(prg, "loaduv", &err));

@ -8,7 +8,7 @@
void transform_init(Transform* s, cl_context ctx, cl_device_id device_id) {
memset(s, 0, sizeof(*s));
cl_program prg = CLU_LOAD_FROM_FILE(ctx, device_id, "transforms/transform.cl", "");
cl_program prg = cl_program_from_file(ctx, device_id, "transforms/transform.cl", "");
s->krnl = CL_CHECK_ERR(clCreateKernel(prg, "warpPerspective", &err));
// done with this
CL_CHECK(clReleaseProgram(prg));

Loading…
Cancel
Save