From 2d2d579c4ad7f6b1b5aeae2605b0632fb4b05ad7 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Thu, 5 Dec 2019 12:06:17 +0000 Subject: [PATCH] base, gpu-compute: Move gpu AMOs into the generic header Change-Id: I10d8aeaae83c232141ddd2fd21ee43bed8712539 Signed-off-by: Giacomo Travaglini Reviewed-by: Nikos Nikoleris Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23565 Reviewed-by: Daniel Carvalho Reviewed-by: Jason Lowe-Power Reviewed-by: Anthony Gutierrez Maintainer: Jason Lowe-Power Maintainer: Anthony Gutierrez Tested-by: kokoro --- src/base/amo.hh | 114 ++++++++++++++++++++++++++++++++ src/gpu-compute/gpu_dyn_inst.hh | 112 +------------------------------ 2 files changed, 115 insertions(+), 111 deletions(-) diff --git a/src/base/amo.hh b/src/base/amo.hh index 624c755ed..ec0598199 100644 --- a/src/base/amo.hh +++ b/src/base/amo.hh @@ -1,4 +1,7 @@ /* + * Copyright (c) 2015-2017 Advanced Micro Devices, Inc. + * All rights reserved. + * * Copyright (c) 2003-2005 The Regents of The University of Michigan * All rights reserved. * @@ -26,6 +29,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Authors: Nathan Binkert + * Anthony Gutierrez */ #ifndef __BASE_AMO_HH__ @@ -109,6 +113,116 @@ class AtomicGenericPair3Op : public TypedAtomicOpFunctor std::function&, std::array)> op; }; +template +class AtomicOpAnd : public TypedAtomicOpFunctor +{ + public: + T a; + AtomicOpAnd(T _a) : a(_a) { } + void execute(T *b) { *b &= a; } + AtomicOpFunctor* clone () { return new AtomicOpAnd(a); } +}; + +template +class AtomicOpOr : public TypedAtomicOpFunctor +{ + public: + T a; + AtomicOpOr(T _a) : a(_a) { } + void execute(T *b) { *b |= a; } + AtomicOpFunctor* clone () { return new AtomicOpOr(a); } +}; + +template +class AtomicOpXor : public TypedAtomicOpFunctor +{ + public: + T a; + AtomicOpXor(T _a) : a(_a) {} + void execute(T *b) { *b ^= a; } + AtomicOpFunctor* clone () { return new AtomicOpXor(a); } +}; + +template +class AtomicOpExch : public TypedAtomicOpFunctor +{ + public: + T a; + AtomicOpExch(T _a) : a(_a) { } + void execute(T *b) { *b = a; } + AtomicOpFunctor* clone () { return new AtomicOpExch(a); } +}; + +template +class AtomicOpAdd : public TypedAtomicOpFunctor +{ + public: + T a; + AtomicOpAdd(T _a) : a(_a) { } + void execute(T *b) { *b += a; } + AtomicOpFunctor* clone () { return new AtomicOpAdd(a); } +}; + +template +class AtomicOpSub : public TypedAtomicOpFunctor +{ + public: + T a; + AtomicOpSub(T _a) : a(_a) { } + void execute(T *b) { *b -= a; } + AtomicOpFunctor* clone () { return new AtomicOpSub(a); } +}; + +template +class AtomicOpInc : public TypedAtomicOpFunctor +{ + public: + AtomicOpInc() { } + void execute(T *b) { *b += 1; } + AtomicOpFunctor* clone () { return new AtomicOpInc(); } +}; + +template +class AtomicOpDec : public TypedAtomicOpFunctor +{ + public: + AtomicOpDec() {} + void execute(T *b) { *b -= 1; } + AtomicOpFunctor* clone () { return new AtomicOpDec(); } +}; + +template +class AtomicOpMax : public TypedAtomicOpFunctor +{ + public: + T a; + AtomicOpMax(T _a) : a(_a) { } + + void + execute(T *b) + { + if (a > *b) + *b = a; + } + AtomicOpFunctor* clone () { return new AtomicOpMax(a); } +}; + +template +class AtomicOpMin : public TypedAtomicOpFunctor +{ + public: + T a; + AtomicOpMin(T _a) : a(_a) {} + + void + execute(T *b) + { + if (a < *b) + *b = a; + } + AtomicOpFunctor* clone () { return new AtomicOpMin(a); } +}; + typedef std::unique_ptr AtomicOpFunctorPtr; #endif // __BASE_AMO_HH__ diff --git a/src/gpu-compute/gpu_dyn_inst.hh b/src/gpu-compute/gpu_dyn_inst.hh index 9e63c4459..1f7bb65ca 100644 --- a/src/gpu-compute/gpu_dyn_inst.hh +++ b/src/gpu-compute/gpu_dyn_inst.hh @@ -39,6 +39,7 @@ #include #include +#include "base/amo.hh" #include "base/logging.hh" #include "enums/MemType.hh" #include "enums/StorageClassType.hh" @@ -47,37 +48,6 @@ class GPUStaticInst; -template -class AtomicOpAnd : public TypedAtomicOpFunctor -{ - public: - T a; - - AtomicOpAnd(T _a) : a(_a) { } - void execute(T *b) { *b &= a; } - AtomicOpFunctor* clone () { return new AtomicOpAnd(a); } -}; - -template -class AtomicOpOr : public TypedAtomicOpFunctor -{ - public: - T a; - AtomicOpOr(T _a) : a(_a) { } - void execute(T *b) { *b |= a; } - AtomicOpFunctor* clone () { return new AtomicOpOr(a); } -}; - -template -class AtomicOpXor : public TypedAtomicOpFunctor -{ - public: - T a; - AtomicOpXor(T _a) : a(_a) {} - void execute(T *b) { *b ^= a; } - AtomicOpFunctor* clone () { return new AtomicOpXor(a); } -}; - template class AtomicOpCAS : public TypedAtomicOpFunctor { @@ -108,86 +78,6 @@ class AtomicOpCAS : public TypedAtomicOpFunctor AtomicOpFunctor* clone () { return new AtomicOpCAS(c, s, computeUnit); } }; -template -class AtomicOpExch : public TypedAtomicOpFunctor -{ - public: - T a; - AtomicOpExch(T _a) : a(_a) { } - void execute(T *b) { *b = a; } - AtomicOpFunctor* clone () { return new AtomicOpExch(a); } -}; - -template -class AtomicOpAdd : public TypedAtomicOpFunctor -{ - public: - T a; - AtomicOpAdd(T _a) : a(_a) { } - void execute(T *b) { *b += a; } - AtomicOpFunctor* clone () { return new AtomicOpAdd(a); } -}; - -template -class AtomicOpSub : public TypedAtomicOpFunctor -{ - public: - T a; - AtomicOpSub(T _a) : a(_a) { } - void execute(T *b) { *b -= a; } - AtomicOpFunctor* clone () { return new AtomicOpSub(a); } -}; - -template -class AtomicOpInc : public TypedAtomicOpFunctor -{ - public: - AtomicOpInc() { } - void execute(T *b) { *b += 1; } - AtomicOpFunctor* clone () { return new AtomicOpInc(); } -}; - -template -class AtomicOpDec : public TypedAtomicOpFunctor -{ - public: - AtomicOpDec() {} - void execute(T *b) { *b -= 1; } - AtomicOpFunctor* clone () { return new AtomicOpDec(); } -}; - -template -class AtomicOpMax : public TypedAtomicOpFunctor -{ - public: - T a; - AtomicOpMax(T _a) : a(_a) { } - - void - execute(T *b) - { - if (a > *b) - *b = a; - } - AtomicOpFunctor* clone () { return new AtomicOpMax(a); } -}; - -template -class AtomicOpMin : public TypedAtomicOpFunctor -{ - public: - T a; - AtomicOpMin(T _a) : a(_a) {} - - void - execute(T *b) - { - if (a < *b) - *b = a; - } - AtomicOpFunctor* clone () { return new AtomicOpMin(a); } -}; - typedef enum { VT_32, -- 2.30.2