Skip to content

Commit

Permalink
Merge branch '48-fix_address_overflow' into 'master'
Browse files Browse the repository at this point in the history
Avoid address overflow

See merge request tech/adaskit/libSGM!66
  • Loading branch information
atakagi-fixstars committed Aug 21, 2023
2 parents 0a1cd3e + 99be2de commit 5ec81db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/winner_takes_all.cu
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ __global__ void winner_takes_all_kernel(
? REDUCTION_PER_THREAD
: ACCUMULATION_INTERVAL;

const unsigned int cost_step = MAX_DISPARITY * width * height;
const size_t cost_step = static_cast<size_t>(MAX_DISPARITY) * width * height;
const unsigned int warp_id = threadIdx.x / WARP_SIZE;
const unsigned int lane_id = threadIdx.x % WARP_SIZE;

Expand Down
4 changes: 2 additions & 2 deletions test/host_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class HostImage
memcpy(rhs.data, data, elemSize(type) * rows * step);
}

template <typename T> T* ptr(int y = 0) { return (T*)data + y * step; }
template <typename T> const T* ptr(int y = 0) const { return (T*)data + y * step; }
template <typename T> T* ptr(int y = 0) { return (T*)data + y * (size_t)step; }
template <typename T> const T* ptr(int y = 0) const { return (T*)data + y * (size_t)step; }

void* data;
int rows, cols, step;
Expand Down
10 changes: 5 additions & 5 deletions test/test_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ template <typename T> constexpr T max_of() { return std::numeric_limits<T>::max(
template <> constexpr uint8_t max_of() { return 255; }

template <typename T>
static void random_fill_(T* dst, int n, T minv = min_of<T>(), T maxv = max_of<T>())
static void random_fill_(T* dst, size_t n, T minv = min_of<T>(), T maxv = max_of<T>())
{
std::uniform_int_distribution<T> dist(minv, maxv);
for (int i = 0; i < n; ++i)
for (size_t i = 0; i < n; ++i)
dst[i] = dist(g_engine);
}

template <>
void random_fill_(uint8_t* dst, int n, uint8_t minv, uint8_t maxv)
void random_fill_(uint8_t* dst, size_t n, uint8_t minv, uint8_t maxv)
{
std::uniform_int_distribution<uint32_t> dist(minv, maxv);
for (int i = 0; i < n; ++i)
for (size_t i = 0; i < n; ++i)
dst[i] = static_cast<uint8_t>(dist(g_engine));
}

template <typename T>
static void random_fill_(sgm::HostImage& image, T minv = min_of<T>(), T maxv = max_of<T>())
{
random_fill_(image.ptr<T>(), image.rows * image.step, minv, maxv);
random_fill_(image.ptr<T>(), image.rows * (size_t)image.step, minv, maxv);
}

static void random_fill(sgm::HostImage& image)
Expand Down

0 comments on commit 5ec81db

Please sign in to comment.