<commit_before>/**
* Copyright (C) Mellanox Technologies Ltd. 2001-2014.  ALL RIGHTS RESERVED.
*
* $COPYRIGHT$
* $HEADER$
*/

#include "ib_context.h"
#include "ib_verbs.h"

#include <uct/tl/context.h>
#include <ucs/type/component.h>
#include <ucs/debug/memtrack.h>


ucs_status_t uct_ib_query_resources(uct_context_h context, unsigned flags,
                                    uct_resource_desc_t **resources_p,
                                    unsigned *num_resources_p)
{
    uct_ib_context_t *ibctx = ucs_component_get(context, ib, uct_ib_context_t);
    uct_resource_desc_t *resources, *rsc;
    ucs_status_t status;
    unsigned num_resources;
    unsigned resource_index;
    uct_ib_device_t *dev;
    unsigned dev_index;
    uint8_t port_num;

    /* First pass: count ports */
    num_resources = 0;
    for (dev_index = 0; dev_index < ibctx->num_devices; ++dev_index) {
        dev = ibctx->devices[dev_index];
        for (port_num = dev->first_port; port_num < dev->first_port + dev->num_ports;
                        ++port_num)
        {
            if (uct_ib_device_port_check(dev, port_num, flags) == UCS_OK) {
                ++num_resources;
            }
        }
    }

    /* Allocate resources array */
    resources = ucs_calloc(num_resources, sizeof(uct_resource_desc_t), "resource desc");
    if (resources == NULL) {
        status = UCS_ERR_NO_MEMORY;
        goto err;
    }

    /* Second pass: fill port information */
    num_resources  = 0;
    resource_index = 0;
    for (dev_index = 0; dev_index < ibctx->num_devices; ++dev_index) {
        dev = ibctx->devices[dev_index];
        for (port_num = dev->first_port; port_num < dev->first_port + dev->num_ports;
                        ++port_num)
        {
            if (uct_ib_device_port_check(dev, port_num, flags) == UCS_OK) {
                rsc = &resources[resource_index++];
                status = uct_ib_device_port_get_resource(dev, port_num, rsc);
                if (status == UCS_OK) {
                    num_resources++;
                }
            }
        }
    }

    if (num_resources == 0) {
        ucs_debug("There are no compatible ports for this transport.");
        status = UCS_ERR_NO_DEVICE;
        goto err_free;
    }

    *num_resources_p = num_resources;
    *resources_p     = resources;
    return UCS_OK;

err_free:
    ucs_free(resources);
err:
    return status;
}

<commit_msg>UCT: apply CR comments<commit_after>/**
* Copyright (C) Mellanox Technologies Ltd. 2001-2014.  ALL RIGHTS RESERVED.
*
* $COPYRIGHT$
* $HEADER$
*/

#include "ib_context.h"
#include "ib_verbs.h"

#include <uct/tl/context.h>
#include <ucs/type/component.h>
#include <ucs/debug/memtrack.h>


ucs_status_t uct_ib_query_resources(uct_context_h context, unsigned flags,
                                    uct_resource_desc_t **resources_p,
                                    unsigned *num_resources_p)
{
    uct_ib_context_t *ibctx = ucs_component_get(context, ib, uct_ib_context_t);
    uct_resource_desc_t *resources, *rsc;
    ucs_status_t status;
    unsigned max_resources;
    unsigned num_resources;
    uct_ib_device_t *dev;
    unsigned dev_index;
    uint8_t port_num;

    /* First pass: count the upper limit of ports to be used */
    max_resources = 0;
    for (dev_index = 0; dev_index < ibctx->num_devices; ++dev_index) {
        dev = ibctx->devices[dev_index];
        for (port_num = dev->first_port; port_num < dev->first_port + dev->num_ports;
                        ++port_num)
        {
            if (uct_ib_device_port_check(dev, port_num, flags) == UCS_OK) {
                ++max_resources;
            }
        }
    }

    /* Allocate resources array */
    resources = ucs_calloc(max_resources, sizeof(uct_resource_desc_t), "resource desc");
    if (resources == NULL) {
        status = UCS_ERR_NO_MEMORY;
        goto err;
    }

    /* Second pass: fill port information */
    num_resources = 0;
    for (dev_index = 0; dev_index < ibctx->num_devices; ++dev_index) {
        dev = ibctx->devices[dev_index];
        for (port_num = dev->first_port; port_num < dev->first_port + dev->num_ports;
                        ++port_num)
        {
            if (uct_ib_device_port_check(dev, port_num, flags) == UCS_OK) {
                rsc = &resources[num_resources];
                status = uct_ib_device_port_get_resource(dev, port_num, rsc);
                if (status == UCS_OK) {
                    num_resources++;
                }
            }
        }
    }

    if (num_resources == 0) {
        ucs_debug("There are no compatible ports for this transport.");
        status = UCS_ERR_NO_DEVICE;
        goto err_free;
    }

    *num_resources_p = num_resources;
    *resources_p     = resources;
    return UCS_OK;

err_free:
    ucs_free(resources);
err:
    return status;
}


{'fraction_non_alphanumeric': 0.10607940446650124, 'fraction_numerical': 0.0059966914805624485, 'mean_word_length': 2.2096881220968814, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4200645', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1579, 'n_words': 324}