Skip to content

Commit

Permalink
Make sure Rng is seeded the same way on 32/64-bit (#3693)
Browse files Browse the repository at this point in the history
(this will make transform_fuzzer corpora more cross-pollinating)

(cherry picked from commit caecd25758256bcfdb0ba96e55331a49309a204f)
eustas committed Dec 5, 2024
1 parent eeb331c commit 7ea4104
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/base/random.h
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@

namespace jxl {
struct Rng {
explicit Rng(size_t seed)
explicit Rng(uint64_t seed)
: s{static_cast<uint64_t>(0x94D049BB133111EBull),
static_cast<uint64_t>(0xBF58476D1CE4E5B9ull) + seed} {}

2 changes: 1 addition & 1 deletion lib/extras/butteraugli_test.cc
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ StatusOr<Image3F> GetColorImage(const PackedPixelFile& ppf) {
return color;
}

void AddUniformNoise(Image3F* img, float d, size_t seed) {
void AddUniformNoise(Image3F* img, float d, uint64_t seed) {
Rng generator(seed);
for (size_t y = 0; y < img->ysize(); ++y) {
for (int c = 0; c < 3; ++c) {
3 changes: 2 additions & 1 deletion tools/gauss_blur_test.cc
Original file line number Diff line number Diff line change
@@ -511,7 +511,8 @@ void TestRandom(size_t xsize, size_t ysize, float min, float max, double sigma,
min, max, sigma);
JXL_TEST_ASSIGN_OR_DIE(ImageF in,
ImageF::Create(memory_manager, xsize, ysize));
RandomFillImage(&in, min, max, 65537 + xsize * 129 + ysize);
RandomFillImage(&in, min, max,
static_cast<uint64_t>(65537) + xsize * 129 + ysize);
// FastGaussian/Convolve handle borders differently, so keep those pixels 0.
const size_t border = 4 * sigma;
SetBorder(border, 0.0f, &in);
1 change: 1 addition & 0 deletions tools/ssimulacra2.cc
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ updated in April 2023.
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <hwy/aligned_allocator.h>
#include <utility>

#include "lib/base/compiler_specific.h"
8 changes: 5 additions & 3 deletions tools/tracking_memory_manager.cc
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

#include "tools/tracking_memory_manager.h"

#include <cstdint>
#include <mutex>

#include "lib/base/memory_manager.h"
@@ -14,7 +15,7 @@ namespace jpegxl {
namespace tools {

TrackingMemoryManager::TrackingMemoryManager(JxlMemoryManager* inner,
size_t cap)
uint64_t cap)
: cap_(cap), inner_(inner) {
outer_.opaque = reinterpret_cast<void*>(this);
outer_.alloc = &Alloc;
@@ -30,8 +31,9 @@ void* TrackingMemoryManager::Alloc(void* opaque, size_t size) {
reinterpret_cast<TrackingMemoryManager*>(opaque);
{
std::lock_guard<std::mutex> guard(self->numbers_mutex_);
size_t new_bytes_in_use = self->bytes_in_use_ + size;
if (self->cap_ && new_bytes_in_use > self->cap_) {
uint64_t new_bytes_in_use = self->bytes_in_use_ + size;
if (new_bytes_in_use < size ||
(self->cap_ && new_bytes_in_use > self->cap_)) {
// Soft "OOM"
return nullptr;
}
2 changes: 1 addition & 1 deletion tools/tracking_memory_manager.h
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ namespace tools {

class TrackingMemoryManager {
public:
explicit TrackingMemoryManager(JxlMemoryManager* inner, size_t cap = 0);
explicit TrackingMemoryManager(JxlMemoryManager* inner, uint64_t cap = 0);

JxlMemoryManager* get() { return &outer_; }

0 comments on commit 7ea4104

Please sign in to comment.