Commit 36e224ae authored by kolusask's avatar kolusask
Browse files

Define HashGraphS members

parent 5c2ab2b3
Loading
Loading
Loading
Loading
+9 −8
Original line number Original line Diff line number Diff line
@@ -9,6 +9,7 @@


#include <vector>
#include <vector>



using namespace TNL::Algorithms::Segments;
using namespace TNL::Algorithms::Segments;
using namespace TNL::Containers;
using namespace TNL::Containers;


@@ -24,13 +25,12 @@ class HashGraphS {


  public:
  public:
    void debug_print() const {
    void debug_print() const {
      std::cout << "CONTENT" << std::endl;
      // std::cout << "CONTENT" << std::endl;
      std::cout << m_content << std::endl;
      // std::cout << m_content << std::endl;
      std::cout << "ITEMS" << std::endl;
      // std::cout << "ITEMS" << std::endl;
      std::cout << m_items << std::endl;
      // std::cout << m_items << std::endl;
      std::cout << "OFFSET" << std::endl;
      // std::cout << "OFFSET" << std::endl;
      std::cout << m_offset << std::endl;
      // std::cout << m_offset << std::endl;
      
    }
    }
    int duplicates() const;
    int duplicates() const;


@@ -39,9 +39,10 @@ class HashGraphS {
    bool find(const Key& key, ArrayView<Item, Device> item) const;
    bool find(const Key& key, ArrayView<Item, Device> item) const;


  private:
  private:
    Array<Item> m_table;
    Array<Item, Device> m_content;
    Vector<int, Device> m_segmentSizes;
    Vector<int, Device> m_segmentSizes;
    CSR<Device, int> m_csr;
    CSR<Device, int> m_csr;
    Array<int, Device> m_table;
};
};




+4 −0
Original line number Original line Diff line number Diff line
@@ -11,6 +11,10 @@


template<typename Item, typename Key, typename Device>
template<typename Item, typename Key, typename Device>
HashGraphS<Item, Key, Device>::HashGraphS(const Array<Item, Device>& items) :
HashGraphS<Item, Key, Device>::HashGraphS(const Array<Item, Device>& items) :
            m_content(items),
            m_segmentSizes(items.getSize()),
            m_csr(items.getSize()),
            m_table(m_csr.getStorageSize()),
            m_view(*this, items.getConstView()) {}
            m_view(*this, items.getConstView()) {}


template<typename Item, typename Key, typename Device>
template<typename Item, typename Key, typename Device>
+4 −2
Original line number Original line Diff line number Diff line
@@ -31,12 +31,14 @@ class HashGraphSView {


    void build();
    void build();


    void fill_offset(const ArrayView<int, Device>& counter);
    void fill_csr();


  private:
  private:
    ArrayView<Item> m_table;
    ArrayView<Item, Device> m_content;
    Array<Item, Device> m_table;
    CSRView<Device, int> m_csr;
    CSRView<Device, int> m_csr;
    VectorView<int, Device> m_segmentsSizes;
    VectorView<int, Device> m_segmentsSizes;
    HashFunction<Key> m_hash;
};
};




+16 −25
Original line number Original line Diff line number Diff line
#pragma once
#pragma once


#include "HashGraphV1View.h"
#include "HashGraphSView.h"


#include <TNL/Algorithms/ParallelFor.h>
#include <TNL/Algorithms/ParallelFor.h>




template<typename Item, typename Key, typename Device>
template<typename Item, typename Key, typename Device>
HashGraphV1View<Item, Key, Device>::HashGraphV1View(TableType& table,
HashGraphSView<Item, Key, Device>::HashGraphSView(TableType& table,
                                                    const typename Array<Item, Device>::ConstViewType items, 
                                                    const typename Array<Item, Device>::ConstViewType items) :
                                                    ArrayView<int, Device> hashes,
            m_content(table.m_table.getView()),
                                                    ArrayView<int, Device> counter) :
            m_table(table.m_table.getView()),
            m_content(table.m_content.getView()),
            m_csr(table.m_csr.getView()),
            m_items(table.m_items.getView()),
            m_segmentsSizes(table.m_segmentSizes.getView()),
            m_offset(table.m_offset.getView()),
            m_hash(31, 10538, items.getSize()) {
            m_hash(31, 10538, items.getSize()) {
    build(items, hashes, counter);
    build();
}
}


template<typename Item, typename Key, typename Device>
template<typename Item, typename Key, typename Device>
void HashGraphV1View<Item, Key, Device>::build(const typename Array<Item, Device>::ConstViewType input,
void HashGraphSView<Item, Key, Device>::build() {
                                               ArrayView<int, Device> hashes,
                                               ArrayView<int, Device> counter) {
    
    auto content = m_content;
    auto fill_content = [content, input] __cuda_callable__ (int i) mutable {
        content[i] = input[i];
    };
    TNL::Algorithms::ParallelFor<Device>::exec(0, input.getSize(), fill_content);
    auto hash = m_hash;
    auto hash = m_hash;
    auto init_hashes = [hash, hashes, input] __cuda_callable__ (int i) mutable {
    auto init_hashes = [hash, hashes, input] __cuda_callable__ (int i) mutable {
        hashes[i] = hash(input[i].key);
        hashes[i] = hash(input[i].key);
    };
    };
    TNL::Algorithms::ParallelFor<Device>::exec(0, m_items.getSize(), init_hashes);
    TNL::Algorithms::ParallelFor<Device>::exec(0, m_items.getSize(), init_hashes);
    counter.setValue(0);
    m_segmentsSizes.setValue(0);
    auto count_hashes = [hashes, counter] __cuda_callable__ (int i) mutable {
    auto count_hashes = [hashes, counter] __cuda_callable__ (int i) mutable {
        #ifdef __CUDA_ARCH__
        #ifdef __CUDA_ARCH__
        atomicAdd(&counter[hashes[i]], 1);
        atomicAdd(&counter[hashes[i]], 1);
        #else
        #else
        counter[hashes[i]]++;
        m_segmentSizes[hashes[i]]++;
        #endif
        #endif
    };
    };
    TNL::Algorithms::ParallelFor<Device>::exec(0, hashes.getSize(), count_hashes);
    TNL::Algorithms::ParallelFor<Device>::exec(0, hashes.getSize(), count_hashes);
    fill_offset(counter);
    fill_csr();
    counter.setValue(0, 0, counter.getSize());
    counter.setValue(0, 0, counter.getSize());
    auto offset = m_offset;
    auto offset = m_offset;
    auto items = m_items;
    auto items = m_items;
@@ -57,10 +48,10 @@ void HashGraphV1View<Item, Key, Device>::build(const typename Array<Item, Device
}
}


template<typename Item, typename Key, typename Device>
template<typename Item, typename Key, typename Device>
HashGraphV1View<Item, Key, Device>::~HashGraphV1View() {}
HashGraphSView<Item, Key, Device>::~HashGraphSView() {}


template<typename Item, typename Key, typename Device>
template<typename Item, typename Key, typename Device>
void HashGraphV1View<Item, Key, Device>::fill_offset(const ArrayView<int, Device>& counter) {
void HashGraphSView<Item, Key, Device>::fill_csr() {
    auto offset = m_offset;
    auto offset = m_offset;
    auto fill = [offset, counter] __cuda_callable__ (int i) mutable {
    auto fill = [offset, counter] __cuda_callable__ (int i) mutable {
        offset[i] = i >= counter.getSize() ? 0 : counter[i];
        offset[i] = i >= counter.getSize() ? 0 : counter[i];
@@ -89,12 +80,12 @@ void HashGraphV1View<Item, Key, Device>::fill_offset(const ArrayView<int, Device
}
}


template<typename Item, typename Key, typename Device>
template<typename Item, typename Key, typename Device>
int HashGraphV1View<Item, Key, Device>::duplicates() const {
int HashGraphSView<Item, Key, Device>::duplicates() const {
    return -1;
    return -1;
}
}


template<typename Item, typename Key, typename Device>
template<typename Item, typename Key, typename Device>
bool HashGraphV1View<Item, Key, Device>::find(const Key& key, ArrayView<Item, Device> item) const {
bool HashGraphSView<Item, Key, Device>::find(const Key& key, ArrayView<Item, Device> item) const {
    int hash = m_hash(key);
    int hash = m_hash(key);
    int end = m_offset.getElement(hash + 1);
    int end = m_offset.getElement(hash + 1);
    auto content = m_content;
    auto content = m_content;