<commit_before>/**
* Copyright (C) Mellanox Technologies Ltd. 2001-2015.  ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/

#define __STDC_LIMIT_MACROS

#include "ucp_test.h"

#include <algorithm>

extern "C" {
#include <ucp/wireup/address.h>
#include <ucp/proto/proto.h>
}

class test_ucp_wireup : public ucp_test {
public:
    static std::vector<ucp_test_param>
    enum_test_params(const ucp_params_t& ctx_params,
                     const std::string& name,
                     const std::string& test_case_name,
                     const std::string& tls);

protected:
    enum {
        TEST_RMA,
        TEST_TAG
    };

    typedef uint64_t               elem_type;
    typedef std::vector<elem_type> vec_type;

    static const size_t BUFFER_LENGTH    = 16384;
    static const ucp_datatype_t DT_U64 = ucp_dt_make_contig(sizeof(elem_type));
    static const uint64_t TAG          = 0xdeadbeef;
    static const elem_type SEND_DATA   = 0xdeadbeef12121212ull;

    virtual void init();
    virtual void cleanup();

    void send_nb(ucp_ep_h ep, size_t length, int repeat, std::vector<void*>& reqs);

    void send_b(ucp_ep_h ep,         size_t length, int repeat);

    void recv_b(ucp_worker_h worker, size_t length, int repeat);

    void send_recv(ucp_ep_h ep, ucp_worker_h worker, size_t vecsize, int repeat);

    void disconnect(ucp_ep_h ep);

    void waitall(std::vector<void*> reqs);

private:
    vec_type   m_send_data;
    vec_type   m_recv_data;
    size_t     m_max_send;
    ucp_mem_h  m_memh1, m_memh2;
    ucp_rkey_h m_rkey1, m_rkey2;

    void clear_recv_data();

    ucp_rkey_h get_rkey(ucp_mem_h memh);

    static void send_completion(void *request, ucs_status_t status);

    static void recv_completion(void *request, ucs_status_t status,
                                ucp_tag_recv_info_t *info);
};

std::vector<ucp_test_param>
test_ucp_wireup::enum_test_params(const ucp_params_t& ctx_params,
                                  const std::string& name,
                                  const std::string& test_case_name,
                                  const std::string& tls)
{
    std::vector<ucp_test_param> result;
    ucp_params_t tmp_ctx_params = ctx_params;

    tmp_ctx_params.features = UCP_FEATURE_RMA;
    generate_test_params_variant(tmp_ctx_params, name, test_case_name + "/rma",
                                 tls, TEST_RMA, result);

    tmp_ctx_params.features = UCP_FEATURE_TAG;
    generate_test_params_variant(tmp_ctx_params, name, test_case_name + "/tag",
                                 tls, TEST_TAG, result);

    return result;
}

void test_ucp_wireup::init() {
    ucp_test::init();

    m_send_data.resize(BUFFER_LENGTH, SEND_DATA);
    m_recv_data.resize(BUFFER_LENGTH, 0);

    if (GetParam().variant == UCP_FEATURE_RMA) {
        ucs_status_t status;

        void *ptr   = &m_recv_data[0];
        size_t size = m_recv_data.size() * sizeof(m_recv_data[0]);

        status = ucp_mem_map(receiver().ucph(), &ptr, size, 0, &m_memh1);
        ASSERT_UCS_OK(status);

        status = ucp_mem_map(sender().ucph(), &ptr, size, 0, &m_memh2);
        ASSERT_UCS_OK(status);

        m_rkey1 = get_rkey(m_memh1);
        m_rkey2 = get_rkey(m_memh2);
    }
}

ucp_rkey_h test_ucp_wireup::get_rkey(ucp_mem_h memh)
{
    void *rkey_buffer;
    size_t rkey_size;<commit_msg>TEST/WIREUP: Fix compilation on gcc 6.1.0<commit_after>/**
* Copyright (C) Mellanox Technologies Ltd. 2001-2015.  ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/

#define __STDC_LIMIT_MACROS

#include "ucp_test.h"

#include <algorithm>

extern "C" {
#include <ucp/wireup/address.h>
#include <ucp/proto/proto.h>
}

class test_ucp_wireup : public ucp_test {
public:
    static std::vector<ucp_test_param>
    enum_test_params(const ucp_params_t& ctx_params,
                     const std::string& name,
                     const std::string& test_case_name,
                     const std::string& tls);

protected:
    enum {
        TEST_RMA,
        TEST_TAG
    };

    typedef uint64_t               elem_type;
    typedef std::vector<elem_type> vec_type;

    static const size_t BUFFER_LENGTH    = 16384;
    static const ucp_datatype_t DT_U64 = ucp_dt_make_contig(sizeof(elem_type));
    static const uint64_t TAG          = 0xdeadbeef;
    static const elem_type SEND_DATA   = 0xdeadbeef12121212ull;

    virtual void init();
    virtual void cleanup();

    void send_nb(ucp_ep_h ep, size_t length, int repeat, std::vector<void*>& reqs);

    void send_b(ucp_ep_h ep,         size_t length, int repeat);

    void recv_b(ucp_worker_h worker, size_t length, int repeat);

    void send_recv(ucp_ep_h ep, ucp_worker_h worker, size_t vecsize, int repeat);

    void disconnect(ucp_ep_h ep);

    void waitall(std::vector<void*> reqs);

private:
    vec_type   m_send_data;
    vec_type   m_recv_data;
    size_t     m_max_send;
    ucp_mem_h  m_memh1, m_memh2;
    ucp_rkey_h m_rkey1, m_rkey2;

    void clear_recv_data();

    ucp_rkey_h get_rkey(ucp_mem_h memh);

    static void send_completion(void *request, ucs_status_t status);

    static void recv_completion(void *request, ucs_status_t status,
                                ucp_tag_recv_info_t *info);
};

std::vector<ucp_test_param>
test_ucp_wireup::enum_test_params(const ucp_params_t& ctx_params,
                                  const std::string& name,
                                  const std::string& test_case_name,
                                  const std::string& tls)
{
    std::vector<ucp_test_param> result;
    ucp_params_t tmp_ctx_params = ctx_params;

    tmp_ctx_params.features = UCP_FEATURE_RMA;
    generate_test_params_variant(tmp_ctx_params, name, test_case_name + "/rma",
                                 tls, TEST_RMA, result);

    tmp_ctx_params.features = UCP_FEATURE_TAG;
    generate_test_params_variant(tmp_ctx_params, name, test_case_name + "/tag",
                                 tls, TEST_TAG, result);

    return result;
}

void test_ucp_wireup::init() {
    ucp_test::init();

    m_send_data.resize(BUFFER_LENGTH, elem_type(SEND_DATA));
    m_recv_data.resize(BUFFER_LENGTH, 0);

    if (GetParam().variant == UCP_FEATURE_RMA) {
        ucs_status_t status;

        void *ptr   = &m_recv_data[0];
        size_t size = m_recv_data.size() * sizeof(m_recv_data[0]);

        status = ucp_mem_map(receiver().ucph(), &ptr, size, 0, &m_memh1);
        ASSERT_UCS_OK(status);

        status = ucp_mem_map(sender().ucph(), &ptr, size, 0, &m_memh2);
        ASSERT_UCS_OK(status);

        m_rkey1 = get_rkey(m_memh1);
        m_rkey2 = get_rkey(m_memh2);
    }
}

ucp_rkey_h test_ucp_wireup::get_rkey(ucp_mem_h memh)
{
    void *rkey_buffer;
    size_t rkey_size;
{'fraction_non_alphanumeric': 0.09641422407379854, 'fraction_numerical': 0.013539651837524178, 'mean_word_length': 2.7700504767246215, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2867123', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2425, 'n_words': 472}