Commit 66517dfc authored by Zimin Li's avatar Zimin Li
Browse files

issue/46: Fix omp for loop iterator to ssize_t in calculate()

issue/46: Change ssize_t to ptrdiff_t for the counter in openmp loop
parent 10c9525f
...@@ -26,13 +26,23 @@ jobs: ...@@ -26,13 +26,23 @@ jobs:
- name: check format - name: check format
run: python3 scripts/format.py --path src --check run: python3 scripts/format.py --path src --check
- name: Install OpenMP
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y libomp-dev
- name: Install LLVM for OpenMP (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install llvm -y
echo "C:\Program Files\LLVM\bin" >> $env:GITHUB_PATH
- name: install xmake - name: install xmake
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
with: with:
xmake-version: latest xmake-version: latest
- name: configure xmake - name: configure xmake
run: xmake f -cv run: xmake f --omp=y -cv
- name: build with xmake - name: build with xmake
run: xmake build run: xmake build
......
...@@ -156,10 +156,10 @@ void calculate(BinaryCpuInfo info, void *c, const void *a, const void *b, Args & ...@@ -156,10 +156,10 @@ void calculate(BinaryCpuInfo info, void *c, const void *a, const void *b, Args &
auto a_ = reinterpret_cast<const Tdata *>(a); auto a_ = reinterpret_cast<const Tdata *>(a);
auto b_ = reinterpret_cast<const Tdata *>(b); auto b_ = reinterpret_cast<const Tdata *>(b);
auto c_ = reinterpret_cast<Tdata *>(c); auto c_ = reinterpret_cast<Tdata *>(c);
ssize_t data_size = info.c_data_size; ptrdiff_t data_size = info.c_data_size;
#pragma omp parallel for #pragma omp parallel for
for (ssize_t i = 0; i < data_size; ++i) { for (ptrdiff_t i = 0; i < data_size; ++i) {
size_t a_index = info.broadcasted ? indexToReducedOffset(i, info.ndim, info.c_strides.data(), info.a_strides.data()) size_t a_index = info.broadcasted ? indexToReducedOffset(i, info.ndim, info.c_strides.data(), info.a_strides.data())
: indexToOffset(i, info.ndim, info.a_shape.data(), info.a_strides.data()); : indexToOffset(i, info.ndim, info.a_shape.data(), info.a_strides.data());
size_t b_index = info.broadcasted ? indexToReducedOffset(i, info.ndim, info.c_strides.data(), info.b_strides.data()) size_t b_index = info.broadcasted ? indexToReducedOffset(i, info.ndim, info.c_strides.data(), info.b_strides.data())
......
...@@ -37,3 +37,8 @@ target("infinirt-cpu") ...@@ -37,3 +37,8 @@ target("infinirt-cpu")
set_languages("cxx17") set_languages("cxx17")
add_files("../src/infinirt/cpu/*.cc") add_files("../src/infinirt/cpu/*.cc")
target_end() target_end()
if has_config("omp") then
add_requires("openmp")
add_packages("openmp")
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment