int pocl_cache_create_program_cachedir(cl_program program, unsigned device_i, const char* preprocessed_source, size_t source_len, char* program_bc_path, void** cache_lock) { const char *hash_source = NULL; uint8_t old_build_hash[SHA1_DIGEST_SIZE] = {0}; size_t hs_len = 0; assert(cache_topdir_initialized); if (program->source && preprocessed_source==NULL) { hash_source = program->source; hs_len = strlen(program->source); } else { hash_source = preprocessed_source; hs_len = source_len; } if (program->build_hash[device_i]) memcpy(old_build_hash, program->build_hash[device_i], SHA1_DIGEST_SIZE); build_program_compute_hash(program, device_i, hash_source, hs_len); /* if the old hash is nonzero and different, we must free the built binaries before returning, so that they get loaded from the new location */ if (old_build_hash[0] && memcmp(old_build_hash, program->build_hash[device_i], SHA1_DIGEST_SIZE)) { if (program->binaries[device_i]) { POCL_MEM_FREE(program->binaries[device_i]); program->binary_sizes[device_i] = 0; } pocl_free_llvm_irs(program, device_i); } program_device_dir(program_bc_path, program, device_i, ""); if (pocl_mkdir_p(program_bc_path)) return 1; pocl_cache_program_bc_path(program_bc_path, program, device_i); *cache_lock = pocl_cache_acquire_writer_lock_i(program, device_i); return 0; }
static void clean_program_on_rebuild (cl_program program) { /* if we're rebuilding the program, release the kernels and reset log/status */ size_t i; if ((program->build_status != CL_BUILD_NONE) || program->num_kernels > 0) { /* Spec says: CL_INVALID_OPERATION if there are kernel objects attached to program. ...and we check for that earlier. */ assert (program->kernels == NULL); free_meta (program); program->num_kernels = 0; program->build_status = CL_BUILD_NONE; for (i = 0; i < program->num_devices; ++i) { POCL_MEM_FREE (program->build_log[i]); memset (program->build_hash[i], 0, sizeof (SHA1_digest_t)); if (program->source) { POCL_MEM_FREE (program->binaries[i]); program->binary_sizes[i] = 0; #ifdef OCS_AVAILABLE if (program->llvm_irs[i]) pocl_free_llvm_irs (program, i); #endif POCL_MEM_FREE (program->pocl_binaries[i]); program->pocl_binary_sizes[i] = 0; } } program->main_build_log[0] = 0; } }