Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions humming/csrc/launcher/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ std::tuple<int64_t, std::string> register_kernel(const std::string &cubin_path)
auto path_it = g_path_ids.find(cubin_path);
if (path_it != g_path_ids.end()) return path_it->second;

int64_t hash_id = manual_crc32(cubin_path);
hash_id = (hash_id << 30) + manual_crc32(kernel_name);
int64_t hash_id = get_kernel_registration_id(cubin_path, kernel_name);
auto kernel_it = g_registered_kernels.find(hash_id);
bool no_collision = kernel_it == g_registered_kernels.end() || kernel_it->second.cubin_path == cubin_path;
ASSERT_CHECK(no_collision, "kernel id collision for ", cubin_path);
Expand Down
3 changes: 1 addition & 2 deletions humming/csrc/launcher/process_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ inline std::tuple<int64_t, std::string> register_process_input_kernel(const std:
}
ASSERT_CHECK(!kernel_name.empty(), "no process-input kernel found in ", cubin_path);

int64_t kernel_id = manual_crc32(cubin_path);
kernel_id = (kernel_id << 30) + manual_crc32(kernel_name);
int64_t kernel_id = get_kernel_registration_id(cubin_path, kernel_name);
ProcessInputKernelData metadata = {
reader.getUint32("NUM_THREADS"),
reader.getUint32("SOURCE_DTYPE_ID"),
Expand Down
38 changes: 23 additions & 15 deletions humming/csrc/launcher/utils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <array>
#include <cstdint>
#include <cuda.h>
#include <string>

Expand Down Expand Up @@ -69,27 +71,33 @@ inline CUstream get_current_cuda_stream(int64_t dev) {
#endif
}

uint32_t manual_crc32(const std::string &data) {
static uint32_t table[256];
static bool table_computed = false;

if (!table_computed) {
for (uint32_t i = 0; i < 256; i++) {
uint32_t c = i;
uint64_t manual_crc64(const std::string &data) {
// CRC-64/ECMA-182: non-reflected, with zero initial value and final XOR.
static const auto table = [] {
std::array<uint64_t, 256> values{};
for (uint64_t i = 0; i < values.size(); i++) {
uint64_t crc = i << 56;
for (int j = 0; j < 8; j++) {
if (c & 1) c = 0xEDB88320L ^ (c >> 1);
else c = c >> 1;
if (crc & (1ULL << 63)) crc = (crc << 1) ^ 0x42F0E1EBA9EA3693ULL;
else crc <<= 1;
}
table[i] = c;
values[i] = crc;
}
table_computed = true;
}
return values;
}();

uint32_t crc = 0xFFFFFFFFL;
uint64_t crc = 0;
for (unsigned char b : data) {
crc = table[(crc ^ b) & 0xFF] ^ (crc >> 8);
crc = table[(crc >> 56) ^ b] ^ (crc << 8);
}
return crc ^ 0xFFFFFFFFL;
return crc;
}

int64_t get_kernel_registration_id(const std::string &cubin_path, const std::string &kernel_name) {
std::string key = cubin_path;
key.push_back('\0');
key.append(kernel_name);
return static_cast<int64_t>(manual_crc64(key) & 0x7FFFFFFFFFFFFFFFULL);
}

uint32_t get_dtype_num_bits(uint32_t dtype_id) {
Expand Down
2 changes: 1 addition & 1 deletion humming/utils/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def popen_and_reap(cmd, **kwargs):
def hash_to_hex(s: str) -> str:
md5 = hashlib.md5()
md5.update(s.encode("utf-8"))
return md5.hexdigest()[0:16]
return md5.hexdigest()


@functools.lru_cache(maxsize=1)
Expand Down
Loading