[Beignet] [PATCH] replace hash_map with map
Song, Ruiling
ruiling.song at intel.com
Wed Dec 24 16:38:14 PST 2014
The patch LGTM
> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Guo Yejun
> Sent: Wednesday, December 24, 2014 4:18 PM
> To: beignet at lists.freedesktop.org
> Cc: Guo, Yejun
> Subject: [Beignet] [PATCH] replace hash_map with map
>
> there is no strong evidence to show hash_map makes better performance
> for beignet, since hash_map requires std::hash which is not supported in
> some g++ old versions, so replace hash_map with map.
>
> Signed-off-by: Guo Yejun <yejun.guo at intel.com>
> ---
> backend/src/CMakeLists.txt | 1 -
> backend/src/backend/program.hpp | 3 +-
> backend/src/ir/unit.hpp | 5 +--
> backend/src/llvm/llvm_gen_backend.hpp | 5 +--
> backend/src/sys/hash_map.hpp | 82
> -----------------------------------
> 5 files changed, 5 insertions(+), 91 deletions(-) delete mode 100644
> backend/src/sys/hash_map.hpp
>
> diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt index
> deba230..bec0d2a 100644
> --- a/backend/src/CMakeLists.txt
> +++ b/backend/src/CMakeLists.txt
> @@ -21,7 +21,6 @@ add_dependencies(beignet_bitcode libocl) set
> (GBE_SRC
> ${ocl_blob_file}
> sys/vector.hpp
> - sys/hash_map.hpp
> sys/map.hpp
> sys/set.hpp
> sys/intrusive_list.hpp
> diff --git a/backend/src/backend/program.hpp
> b/backend/src/backend/program.hpp index 4e6b275..446c521 100644
> --- a/backend/src/backend/program.hpp
> +++ b/backend/src/backend/program.hpp
> @@ -32,7 +32,6 @@
> #include "ir/function.hpp"
> #include "ir/printf.hpp"
> #include "ir/sampler.hpp"
> -#include "sys/hash_map.hpp"
> #include "sys/vector.hpp"
> #include <string>
>
> @@ -307,7 +306,7 @@ namespace gbe {
> /*! Allocate an empty kernel. */
> virtual Kernel *allocateKernel(const std::string &name) = 0;
> /*! Kernels sorted by their name */
> - hash_map<std::string, Kernel*> kernels;
> + map<std::string, Kernel*> kernels;
> /*! Global (constants) outside any kernel */
> ir::ConstantSet *constantSet;
> /*! Use custom allocators */
> diff --git a/backend/src/ir/unit.hpp b/backend/src/ir/unit.hpp index
> b5b0fa9..e2ccbe8 100644
> --- a/backend/src/ir/unit.hpp
> +++ b/backend/src/ir/unit.hpp
> @@ -26,7 +26,6 @@
>
> #include "ir/constant.hpp"
> #include "ir/register.hpp"
> -#include "sys/hash_map.hpp"
> #include "sys/map.hpp"
>
> namespace gbe {
> @@ -41,7 +40,7 @@ namespace ir {
> class Unit : public NonCopyable
> {
> public:
> - typedef hash_map<std::string, Function*> FunctionSet;
> + typedef map<std::string, Function*> FunctionSet;
> /*! Create an empty unit */
> Unit(PointerSize pointerSize = POINTER_32_BITS);
> /*! Release everything (*including* the function pointers) */ @@ -76,7
> +75,7 @@ namespace ir {
> bool getValid() { return valid; }
> private:
> friend class ContextInterface; //!< Can free modify the unit
> - hash_map<std::string, Function*> functions; //!< All the defined
> functions
> + FunctionSet functions; //!< All the defined functions
> ConstantSet constantSet; //!< All the constants defined in the unit
> PointerSize pointerSize; //!< Size shared by all pointers
> GBE_CLASS(Unit);
> diff --git a/backend/src/llvm/llvm_gen_backend.hpp
> b/backend/src/llvm/llvm_gen_backend.hpp
> index 966a06c..e127996 100644
> --- a/backend/src/llvm/llvm_gen_backend.hpp
> +++ b/backend/src/llvm/llvm_gen_backend.hpp
> @@ -37,7 +37,6 @@
> #endif
> #include "sys/platform.hpp"
> #include "sys/map.hpp"
> -#include "sys/hash_map.hpp"
> #include <algorithm>
>
> // LLVM Type
> @@ -57,7 +56,7 @@ namespace gbe
>
> /*! Build the hash map for OCL functions on Gen */
> struct OCLIntrinsicMap {
> - /*! Build the intrinsic hash map */
> + /*! Build the intrinsic map */
> OCLIntrinsicMap(void) {
> #define DECL_LLVM_GEN_FUNCTION(ID, NAME) \
> map.insert(std::make_pair(#NAME, GEN_OCL_##ID)); @@ -65,7 +64,7
> @@ namespace gbe #undef DECL_LLVM_GEN_FUNCTION
> }
> /*! Sort intrinsics with their names */
> - hash_map<std::string, OCLInstrinsic> map;
> + gbe::map<std::string, OCLInstrinsic> map;
> OCLInstrinsic find(const std::string symbol) const {
> auto it = map.find(symbol);
>
> diff --git a/backend/src/sys/hash_map.hpp
> b/backend/src/sys/hash_map.hpp deleted file mode 100644 index
> e153cf3..0000000
> --- a/backend/src/sys/hash_map.hpp
> +++ /dev/null
> @@ -1,82 +0,0 @@
> -/*
> - * Copyright © 2012 Intel Corporation
> - *
> - * This library is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU Lesser General Public
> - * License as published by the Free Software Foundation; either
> - * version 2.1 of the License, or (at your option) any later version.
> - *
> - * This library is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> GNU
> - * Lesser General Public License for more details.
> - *
> - * You should have received a copy of the GNU Lesser General Public
> - * License along with this library. If not, see
> <http://www.gnu.org/licenses/>.
> - *
> - * Author: Benjamin Segovia <benjamin.segovia at intel.com>
> - */
> -
> -/**
> - * \file hash_map.hpp
> - *
> - * \author Benjamin Segovia <benjamin.segovia at intel.com>
> - */
> -
> -#ifndef __GBE_HASH_MAP_HPP__
> -#define __GBE_HASH_MAP_HPP__
> -
> -#include "sys/platform.hpp"
> -
> -#ifdef __MSVC__
> -#include <unordered_map>
> -#else
> -#include <tr1/unordered_map>
> -#endif /* __MSVC__ */
> -
> -namespace gbe
> -{
> - /*! Add specific allocator to the hash map */
> - template <class Key,
> - class T,
> - class Hash = std::hash<Key>,
> - class Pred = std::equal_to<Key>>
> - class hash_map : public
> std::tr1::unordered_map<Key,T,Hash,Pred,Allocator<std::pair<const
> Key,T>>>,
> - public NonCopyable
> - {
> - public:
> - // Typedefs
> - typedef std::pair<const Key, T> value_type;
> - typedef Allocator<value_type> allocator_type;
> - typedef std::tr1::unordered_map<Key,T,Hash,Pred,allocator_type>
> parent_type;
> - typedef typename allocator_type::size_type size_type;
> - typedef Key key_type;
> - typedef T mapped_type;
> - typedef Hash hasher;
> - typedef Pred key_equal;
> -
> - /*! Default constructor */
> - INLINE explicit hash_map(size_type n = 3,
> - const hasher& hf = hasher(),
> - const key_equal& eql = key_equal(),
> - const allocator_type& a =
> allocator_type()) :
> - parent_type(n, hf, eql, a) {}
> - /*! Iteration constructor */
> - template <class InputIterator>
> - INLINE hash_map(InputIterator first,
> - InputIterator last,
> - size_type n = 3,
> - const hasher& hf = hasher(),
> - const key_equal& eql = key_equal(),
> - const allocator_type& a = allocator_type()) :
> - parent_type(first,last,n,hf,eql,a) {}
> -#if 0
> - /*! Copy constructor */
> - INLINE hash_map(const hash_map &other) : parent_type(other) {}
> -#endif
> - GBE_CLASS(hash_map);
> - };
> -} /* namespace gbe */
> -
> -#endif /* __GBE_HASH_MAP_HPP__ */
> -
> --
> 1.9.1
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list