<commit_before>#include "drm_setup.h"
#include "memutil.h"

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

struct drm_test_info *drm_test_setup(int argc, char **argv)
{
    struct drm_test_info *info;
    drmVersionPtr version;

    if (argc < 2) {
        printf("Usage: %s /dev/dri/...\n", argv[0]);
        return NULL;
    }
    info = CALLOC_STRUCT(drm_test_info);
    info->fd = open(argv[1], O_RDWR);
    if (info->fd < 0) {
        fprintf(stdout, "Unable to open %s\n", argv[1]);
        goto out;
    }

    version = drmGetVersion(info->fd);
    if (version) {
        printf("Version: %d.%d.%d\n", version->version_major,
               version->version_minor, version->version_patchlevel);
        printf("  Name: %s\n", version->name);
        printf("  Date: %s\n", version->date);
        printf("  Description: %s\n", version->desc);
        drmFreeVersion(version);
    }

    info->dev = etna_device_new(info->fd);
    if (!info->dev) {
        fprintf(stdout, "Unable to create device\n");
        goto out;
    }

    /* TODO: we assume that core 1 is a 3D+CL capable one.
     * This is pretty much only true for i.MX6q(p).
     * If the tests don't work on your hardware check this carefully.
     */
    info->gpu = etna_gpu_new(info->dev, 1);
    if (!info->gpu) {
        fprintf(stdout, "Unable to create gpu\n");
        goto out_device;
    }

    info->pipe = etna_pipe_new(info->gpu, ETNA_PIPE_3D);
    if (!info->pipe) {
        fprintf(stdout, "Unable to create pipe\n");
        goto out_gpu;
    }

    info->stream = etna_cmd_stream_new(info->pipe, 0x3000, NULL, NULL);
    if (!info->stream) {
        fprintf(stdout, "Unable to create command stream\n");
        goto out_pipe;
    }
    return info;

out_pipe:
    etna_pipe_del(info->pipe);
<commit_msg>Stop hardcoding core number 1<commit_after>#include "drm_setup.h"
#include "memutil.h"

#include <common.xml.h>

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

/** Find first GPU with a 3D pipe */
struct etna_gpu *find_suitable_gpu(struct etna_device *dev)
{
    int core_id = 0;
    while (1) {
        struct etna_gpu *gpu = etna_gpu_new(dev, core_id);
        if (!gpu) { /* No more cores, stop */
            return NULL;
        }
        uint64_t features = 0;
        int rv = etna_gpu_get_param(gpu, ETNA_GPU_FEATURES_0, &features);
        if (rv >= 0 && (features & chipFeatures_PIPE_3D)) {
            return gpu;
        }
        etna_gpu_del(gpu);
    }
}

struct drm_test_info *drm_test_setup(int argc, char **argv)
{
    struct drm_test_info *info;
    drmVersionPtr version;

    if (argc < 2) {
        printf("Usage: %s /dev/dri/...\n", argv[0]);
        return NULL;
    }
    info = CALLOC_STRUCT(drm_test_info);
    info->fd = open(argv[1], O_RDWR);
    if (info->fd < 0) {
        fprintf(stdout, "Unable to open %s\n", argv[1]);
        goto out;
    }

    version = drmGetVersion(info->fd);
    if (version) {
        printf("Version: %d.%d.%d\n", version->version_major,
               version->version_minor, version->version_patchlevel);
        printf("  Name: %s\n", version->name);
        printf("  Date: %s\n", version->date);
        printf("  Description: %s\n", version->desc);
        drmFreeVersion(version);
    }

    info->dev = etna_device_new(info->fd);
    if (!info->dev) {
        fprintf(stdout, "Unable to create device\n");
        goto out;
    }

    info->gpu = find_suitable_gpu(info->dev);
    if (!info->gpu) {
        fprintf(stdout, "Unable to find gpu with 3D pipe\n");
        goto out_device;
    }

    info->pipe = etna_pipe_new(info->gpu, ETNA_PIPE_3D);
    if (!info->pipe) {
        fprintf(stdout, "Unable to create pipe\n");
        goto out_gpu;
    }

    info->stream = etna_cmd_stream_new(info->pipe, 0x3000, NULL, NULL);
    if (!info->stream) {
        fprintf(stdout, "Unable to create command stream\n");
        goto out_pipe;
    }
    return info;

out_pipe:
    etna_pipe_del(info->pipe);

{'fraction_non_alphanumeric': 0.14927245358755645, 'fraction_numerical': 0.009282488710486703, 'mean_word_length': 2.4699738903394257, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5955376', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1401, 'n_words': 328}