示例#1
0
static inline void
build_program_compute_hash(cl_program program)
{
  SHA1_CTX hash_ctx;
  int total_binary_size, i;

  pocl_SHA1_Init(&hash_ctx);

  if (program->source)
    {
      pocl_SHA1_Update(&hash_ctx, (uint8_t*) program->source, strlen(program->source));
    }
  else  /* Program was created with clCreateProgramWithBinary() */
    {
      total_binary_size = 0;
      for (i = 0; i < program->num_devices; ++i)
        total_binary_size += program->binary_sizes[i];

      /* Binaries are stored in continuous chunk of memory starting from binaries[0] */
      pocl_SHA1_Update(&hash_ctx, (uint8_t*) program->binaries[0], total_binary_size);
    }

  if (program->compiler_options)
    pocl_SHA1_Update(&hash_ctx, (uint8_t*) program->compiler_options, 
                     strlen(program->compiler_options));

  /* The kernel compiler work-group function method affects the
     produced binary heavily. */
  const char *wg_method = 
    pocl_get_string_option ("POCL_WORK_GROUP_METHOD", "");

  pocl_SHA1_Update (&hash_ctx, (uint8_t*) wg_method, strlen (wg_method));
  pocl_SHA1_Update (&hash_ctx, (uint8_t*) PACKAGE_VERSION, 
                    strlen (PACKAGE_VERSION));
  pocl_SHA1_Update (&hash_ctx, (uint8_t*) LLVM_VERSION, 
                    strlen (LLVM_VERSION));
  pocl_SHA1_Update (&hash_ctx, (uint8_t*) POCL_BUILD_TIMESTAMP, 
                    strlen (POCL_BUILD_TIMESTAMP));
  /*devices may include their own information to hash */
  for (i = 0; i < program->num_devices; ++i)
    {
      if (program->devices[i]->ops->build_hash)
        program->devices[i]->ops->build_hash (program->devices[i]->data, 
                                              &hash_ctx);
    }
  
  pocl_SHA1_Final(&hash_ctx, program->build_hash);
}
示例#2
0
static inline void
build_program_compute_hash(cl_program program,
                           unsigned   device_i,
                           const char*      preprocessed_source,
                           size_t     source_len)
{
    SHA1_CTX hash_ctx;
    unsigned i;
    cl_device_id device = program->devices[device_i];

    pocl_SHA1_Init(&hash_ctx);

    if (program->source) {
        assert(preprocessed_source);
        assert(source_len > 0);
        pocl_SHA1_Update(&hash_ctx, (uint8_t*)preprocessed_source,
                         source_len);
    } else     { /* Program was created with clCreateProgramWithBinary() */
        assert(program->binaries[device_i]);
        pocl_SHA1_Update(&hash_ctx,
                         (uint8_t*) program->binaries[device_i],
                         program->binary_sizes[device_i]);
    }

    if (program->compiler_options)
        pocl_SHA1_Update(&hash_ctx, (uint8_t*) program->compiler_options,
                         strlen(program->compiler_options));

    /* The kernel compiler work-group function method affects the
       produced binary heavily. */
    const char *wg_method=
        pocl_get_string_option("POCL_WORK_GROUP_METHOD", "");

    pocl_SHA1_Update(&hash_ctx, (uint8_t*) wg_method, strlen(wg_method));
    pocl_SHA1_Update(&hash_ctx, (uint8_t*) PACKAGE_VERSION,
                     strlen(PACKAGE_VERSION));
    pocl_SHA1_Update(&hash_ctx, (uint8_t*) LLVM_VERSION,
                     strlen(LLVM_VERSION));
    pocl_SHA1_Update(&hash_ctx, (uint8_t*) POCL_BUILD_TIMESTAMP,
                     strlen(POCL_BUILD_TIMESTAMP));
    pocl_SHA1_Update(&hash_ctx, (const uint8_t *)POCL_KERNELLIB_SHA1,
                     strlen(POCL_KERNELLIB_SHA1));
    /*devices may include their own information to hash */
    if (device->ops->build_hash)
        device->ops->build_hash(device->data, &hash_ctx);


    uint8_t digest[SHA1_DIGEST_SIZE];
    pocl_SHA1_Final(&hash_ctx, digest);

    unsigned char* hashstr = program->build_hash[device_i];
    for (i=0; i < SHA1_DIGEST_SIZE; i++)
        {
            *hashstr++ = (digest[i] & 0x0F) + 65;
            *hashstr++ = ((digest[i] & 0xF0) >> 4) + 65;
        }
    *hashstr = 0;

    program->build_hash[device_i][2] = '/';

}