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
4 changes: 2 additions & 2 deletions challenges/easy/24_rainbow_table/starter/starter.cu
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <cuda_runtime.h>

__device__ unsigned int fnv1a_hash(int input) {
__device__ unsigned int fnv1a_hash(unsigned int input) {
const unsigned int FNV_PRIME = 16777619;
const unsigned int OFFSET_BASIS = 2166136261;

unsigned int hash = OFFSET_BASIS;

for (int byte_pos = 0; byte_pos < 4; byte_pos++) {
unsigned char byte = (input >> (byte_pos * 8)) & 0xFF;
unsigned char byte = (input >> (byte_pos * 8)) & 0xFFu;
hash = (hash ^ byte) * FNV_PRIME;
}

Expand Down
5 changes: 2 additions & 3 deletions challenges/easy/24_rainbow_table/starter/starter.cute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
import cutlass.cute as cute


def fnv1a_hash_u32_scalar(x):
def fnv1a_hash_u32_scalar(x: cute.Uint32) -> cute.Uint32:
FNV_PRIME = 16777619
OFFSET_BASIS = 2166136261
val = cute.Uint32(x)
hash_val = cute.Uint32(OFFSET_BASIS)
prime = cute.Uint32(FNV_PRIME)
mask = cute.Uint32(0xFF)
for byte_pos in range(4):
byte = (val >> (byte_pos * 8)) & mask
byte = (x >> (byte_pos * 8)) & mask
hash_val = (hash_val ^ byte) * prime
return cute.Uint32(hash_val)

Expand Down
5 changes: 2 additions & 3 deletions challenges/easy/24_rainbow_table/starter/starter.jax.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
def fnv1a_hash(x: jax.Array) -> jax.Array:
FNV_PRIME = jnp.uint32(16777619)
OFFSET_BASIS = jnp.uint32(2166136261)
x_u32 = x.astype(jnp.uint32)
hash_val = jnp.full_like(x_u32, OFFSET_BASIS, dtype=jnp.uint32)
hash_val = jnp.full_like(x, OFFSET_BASIS, dtype=jnp.uint32)

MASK_FF = jnp.uint32(0xFF)
for byte_pos in range(4):
byte = (x_u32 >> jnp.uint32(byte_pos * 8)) & MASK_FF
byte = (x >> jnp.uint32(byte_pos * 8)) & MASK_FF
hash_val = hash_val ^ byte
hash_val = hash_val * FNV_PRIME

Expand Down
4 changes: 2 additions & 2 deletions challenges/easy/24_rainbow_table/starter/starter.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ from std.memory import UnsafePointer
from std.math import ceildiv


def fnv1a_hash(input: Int32) -> UInt32:
def fnv1a_hash(input: UInt32) -> UInt32:
alias FNV_PRIME: UInt32 = 16777619
alias OFFSET_BASIS: UInt32 = 2166136261

var hash: UInt32 = OFFSET_BASIS

for byte_pos in range(4):
var byte_val: UInt32 = UInt32((input >> (byte_pos * 8)) & 0xFF)
var byte_val: UInt32 = (input >> (byte_pos * 8)) & UInt32(0xFF)
hash = (hash ^ byte_val) * FNV_PRIME

return hash
Expand Down
Loading