From 01350664764531831efa4608728edd5a845c43c6 Mon Sep 17 00:00:00 2001 From: "elena.totmenina" Date: Mon, 17 Feb 2020 18:07:39 +0300 Subject: [PATCH 1/8] Fix prange utils --- sdc/utilities/prange_utils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sdc/utilities/prange_utils.py b/sdc/utilities/prange_utils.py index 2380bb513..18258a702 100644 --- a/sdc/utilities/prange_utils.py +++ b/sdc/utilities/prange_utils.py @@ -58,12 +58,15 @@ def get_chunks(size, pool_size=0): if pool_size == 0: pool_size = get_pool_size() - chunk_size = (size - 1) // pool_size + 1 + chunk_size = size // pool_size chunks = [] for i in range(pool_size): start = min(i * chunk_size, size) stop = min((i + 1) * chunk_size, size) + if i == pool_size - 1: + rest = size - size // pool_size + stop = min((i + 1) * chunk_size + rest, size) chunks.append(Chunk(start, stop)) return chunks @@ -75,15 +78,17 @@ def get_chunks_impl(size, pool_size=0): if pool_size == 0: pool_size = get_pool_size() - chunk_size = (size - 1) // pool_size + 1 + chunk_size = size // pool_size chunks = [] for i in range(pool_size): start = min(i * chunk_size, size) stop = min((i + 1) * chunk_size, size) - chunk = Chunk(start, stop) - chunks.append(chunk) + if i == pool_size - 1: + rest = size - size // pool_size + stop = min((i + 1) * chunk_size + rest, size) + chunks.append(Chunk(start, stop)) return chunks - return get_chunks_impl + return get_chunks_impl \ No newline at end of file From 6f6815b98cd673c8316c7bbd0ce2ceec76d4ba09 Mon Sep 17 00:00:00 2001 From: "elena.totmenina" Date: Mon, 17 Feb 2020 19:04:43 +0300 Subject: [PATCH 2/8] wip --- sdc/utilities/prange_utils.py | 89 +++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 26 deletions(-) diff --git a/sdc/utilities/prange_utils.py b/sdc/utilities/prange_utils.py index 18258a702..4d27bca82 100644 --- a/sdc/utilities/prange_utils.py +++ b/sdc/utilities/prange_utils.py @@ -54,6 +54,64 @@ def get_pool_size_impl(): return get_pool_size_impl +# ***************************************************************************** +# Copyright (c) 2020, Intel Corporation All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ***************************************************************************** + + +import numba +import sdc + +from typing import NamedTuple +from sdc.utilities.utils import sdc_overload +from sdc.utilities.utils import sdc_register_jitable + + +class Chunk(NamedTuple): + start: int + stop: int + + +def get_pool_size(): + if sdc.config.config_use_parallel_overloads: + return numba.config.NUMBA_NUM_THREADS + else: + return 1 + + +@sdc_overload(get_pool_size) +def get_pool_size_overload(): + pool_size = get_pool_size() + + def get_pool_size_impl(): + return pool_size + + return get_pool_size_impl + + +@sdc_register_jitable def get_chunks(size, pool_size=0): if pool_size == 0: pool_size = get_pool_size() @@ -62,33 +120,12 @@ def get_chunks(size, pool_size=0): chunks = [] for i in range(pool_size): - start = min(i * chunk_size, size) - stop = min((i + 1) * chunk_size, size) + start = i * chunk_size + stop = (i + 1) * chunk_size if i == pool_size - 1: - rest = size - size // pool_size - stop = min((i + 1) * chunk_size + rest, size) + stop = max(stop, size) chunks.append(Chunk(start, stop)) - return chunks - - -@sdc_overload(get_chunks) -def get_chunks_overload(size, pool_size=0): - def get_chunks_impl(size, pool_size=0): - if pool_size == 0: - pool_size = get_pool_size() - - chunk_size = size // pool_size + chunks.append(Chunk(start, stop)) - chunks = [] - for i in range(pool_size): - start = min(i * chunk_size, size) - stop = min((i + 1) * chunk_size, size) - if i == pool_size - 1: - rest = size - size // pool_size - stop = min((i + 1) * chunk_size + rest, size) - chunks.append(Chunk(start, stop)) - - return chunks - - return get_chunks_impl \ No newline at end of file + return chunks From 007971bfcc2ec3b386c39c7e1c9da2cc13af80c8 Mon Sep 17 00:00:00 2001 From: "elena.totmenina" Date: Mon, 17 Feb 2020 19:07:46 +0300 Subject: [PATCH 3/8] fix --- sdc/utilities/prange_utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdc/utilities/prange_utils.py b/sdc/utilities/prange_utils.py index 4d27bca82..b3dfc41b7 100644 --- a/sdc/utilities/prange_utils.py +++ b/sdc/utilities/prange_utils.py @@ -126,6 +126,4 @@ def get_chunks(size, pool_size=0): stop = max(stop, size) chunks.append(Chunk(start, stop)) - chunks.append(Chunk(start, stop)) - return chunks From 02a6f09c5e0a3d5ede442909f70e736ae2af89b5 Mon Sep 17 00:00:00 2001 From: "elena.totmenina" Date: Mon, 17 Feb 2020 19:09:39 +0300 Subject: [PATCH 4/8] fix --- sdc/utilities/prange_utils.py | 56 ----------------------------------- 1 file changed, 56 deletions(-) diff --git a/sdc/utilities/prange_utils.py b/sdc/utilities/prange_utils.py index b3dfc41b7..f21001eee 100644 --- a/sdc/utilities/prange_utils.py +++ b/sdc/utilities/prange_utils.py @@ -25,62 +25,6 @@ # ***************************************************************************** -import numba -import sdc - -from typing import NamedTuple -from sdc.utilities.utils import sdc_overload - - -class Chunk(NamedTuple): - start: int - stop: int - - -def get_pool_size(): - if sdc.config.config_use_parallel_overloads: - return numba.config.NUMBA_NUM_THREADS - - return 1 - - -@sdc_overload(get_pool_size) -def get_pool_size_overload(): - pool_size = get_pool_size() - - def get_pool_size_impl(): - return pool_size - - return get_pool_size_impl - - -# ***************************************************************************** -# Copyright (c) 2020, Intel Corporation All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# -# Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ***************************************************************************** - - import numba import sdc From bb8880a0e8a426e88c4001aa80eb750993020fc2 Mon Sep 17 00:00:00 2001 From: "elena.totmenina" Date: Tue, 18 Feb 2020 10:56:09 +0300 Subject: [PATCH 5/8] small fixes --- sdc/utilities/prange_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdc/utilities/prange_utils.py b/sdc/utilities/prange_utils.py index f21001eee..db85b99ea 100644 --- a/sdc/utilities/prange_utils.py +++ b/sdc/utilities/prange_utils.py @@ -29,8 +29,7 @@ import sdc from typing import NamedTuple -from sdc.utilities.utils import sdc_overload -from sdc.utilities.utils import sdc_register_jitable +from sdc.utilities.utils import sdc_overload, sdc_register_jitable class Chunk(NamedTuple): @@ -41,8 +40,8 @@ class Chunk(NamedTuple): def get_pool_size(): if sdc.config.config_use_parallel_overloads: return numba.config.NUMBA_NUM_THREADS - else: - return 1 + + return 1 @sdc_overload(get_pool_size) @@ -60,6 +59,7 @@ def get_chunks(size, pool_size=0): if pool_size == 0: pool_size = get_pool_size() + pool_size = min(pool_size, size) chunk_size = size // pool_size chunks = [] From 767c329a57f24de6da75685e644b0f012bf67c63 Mon Sep 17 00:00:00 2001 From: "elena.totmenina" Date: Tue, 18 Feb 2020 12:44:17 +0300 Subject: [PATCH 6/8] fix chunk divide --- sdc/utilities/prange_utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sdc/utilities/prange_utils.py b/sdc/utilities/prange_utils.py index db85b99ea..ee2a4851d 100644 --- a/sdc/utilities/prange_utils.py +++ b/sdc/utilities/prange_utils.py @@ -60,14 +60,15 @@ def get_chunks(size, pool_size=0): pool_size = get_pool_size() pool_size = min(pool_size, size) - chunk_size = size // pool_size + chunk_size = (size - 1)//pool_size + 1 chunks = [] for i in range(pool_size): - start = i * chunk_size - stop = (i + 1) * chunk_size - if i == pool_size - 1: - stop = max(stop, size) + start = i*chunk_size + stop = min((i+1)*chunk_size, size) + if start >= size: + break + chunks.append(Chunk(start, stop)) return chunks From 2f4fd5036cdb63df628ac0ae7b99e6774f88d56e Mon Sep 17 00:00:00 2001 From: "elena.totmenina" Date: Tue, 18 Feb 2020 12:54:56 +0300 Subject: [PATCH 7/8] pep --- sdc/utilities/prange_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdc/utilities/prange_utils.py b/sdc/utilities/prange_utils.py index ee2a4851d..05b1f4919 100644 --- a/sdc/utilities/prange_utils.py +++ b/sdc/utilities/prange_utils.py @@ -68,7 +68,7 @@ def get_chunks(size, pool_size=0): stop = min((i+1)*chunk_size, size) if start >= size: break - + chunks.append(Chunk(start, stop)) return chunks From c777fa61259526fe0bbe73d0c8a910aef8d1d1aa Mon Sep 17 00:00:00 2001 From: "elena.totmenina" Date: Tue, 18 Feb 2020 18:11:20 +0300 Subject: [PATCH 8/8] codestyle fix --- sdc/utilities/prange_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdc/utilities/prange_utils.py b/sdc/utilities/prange_utils.py index 05b1f4919..19c7efbaf 100644 --- a/sdc/utilities/prange_utils.py +++ b/sdc/utilities/prange_utils.py @@ -60,14 +60,14 @@ def get_chunks(size, pool_size=0): pool_size = get_pool_size() pool_size = min(pool_size, size) - chunk_size = (size - 1)//pool_size + 1 + chunk_size = (size - 1) // pool_size + 1 chunks = [] for i in range(pool_size): - start = i*chunk_size - stop = min((i+1)*chunk_size, size) + start = i * chunk_size if start >= size: break + stop = min((i + 1) * chunk_size, size) chunks.append(Chunk(start, stop))