<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

//#include <cilk/cilk.h>
#include <omp.h>

#define RESTRICT

double vdiff(int n, const float * RESTRICT a, const float * RESTRICT b)
{
    double d = 0.0;
    for(int i = 0; i < n; i++) {
        d += (a[i] - b[i]);
    }
    return d;
}

void vadd0(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
    for(int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

void vadd1(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
    #pragma omp parallel for simd
    for(int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

void vadd2(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
    _Cilk_for(int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

void vadd3(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
    #pragma offload target(gfx) in(a,b : length(n)) out(c : length(n)) //pin(a, b, c : length(n))
    _Cilk_for(int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

void vadd4(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
    #pragma omp target map(to:n,a[0:n],b[0:n]) map(from:c[0:n])
    #pragma omp parallel for simd
    for(int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

#if USE_GFX

#include <gfx/gfx_rt.h>

__attribute__((target(gfx_kernel)))
void gfx_vadd5(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
    _Cilk_for(int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

void vadd5(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
    int rc = 0;
    rc = _GFX_share(a, sizeof(float)*n);
    if (rc) printf("_GFX_share returned %#06x\n", -_GFX_get_last_error());
    rc = _GFX_share(b, sizeof(float)*n);
    if (rc) printf("_GFX_share returned %#06x\n", -_GFX_get_last_error());
    rc = _GFX_share(c, sizeof(float)*n);
    if (rc) printf("_GFX_share returned %#06x\n", -_GFX_get_last_error());
    GfxTaskId id = _GFX_offload("gfx_vadd5", a, b, c, n);
    rc = _GFX_wait(id,1e9);
    if (rc) printf("_GFX_wait returned %#06x\n", -_GFX_get_last_error());
    rc = _GFX_unshare(a);
    if (rc) printf("_GFX_unshare returned %#06x\n", -_GFX_get_last_error());
    rc = _GFX_unshare(b);
    if (rc) printf("_GFX_unshare returned %#06x\n", -_GFX_get_last_error());
    rc = _GFX_unshare(c);
    if (rc) printf("_GFX_unshare returned %#06x\n", -_GFX_get_last_error());
}

#endif
int main(int argc, char * argv[])
{
    int n = (argc > 1 ) ? atoi(argv[1]) : 1000;
    float * x  = calloc(n,sizeof(float)); assert(x !=NULL);
    float * y  = calloc(n,sizeof(float)); assert(y !=NULL);
    float * z0 = calloc(n,sizeof(float)); assert(z0!=NULL);
    float * z1 = calloc(n,sizeof(float)); assert(z1!=NULL);
    float * z2 = calloc(n,sizeof(float)); assert(z2!=NULL);
    float * z3 = calloc(n,sizeof(float)); assert(z3!=NULL);
    float * z4 = calloc(n,sizeof(float)); assert(z4!=NULL);
#if USE_GFX
    float * z5 = calloc(n,sizeof(float)); assert(z5!=NULL);<commit_msg>add preprocessor guards<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

//#include <cilk/cilk.h>
#include <omp.h>

#define RESTRICT

double vdiff(int n, const float * RESTRICT a, const float * RESTRICT b)
{
    double d = 0.0;
    for(int i = 0; i < n; i++) {
        d += (a[i] - b[i]);
    }
    return d;
}

void vadd0(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
    for(int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

void vadd1(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
#if defined(_OPENMP) && (_OPENMP >= 201307)
    #pragma omp parallel for simd
#elif defined(_OPENMP)
    #warning No OpenMP simd support!
    #pragma omp parallel for
#else
    #warning No OpenMP support!
#endif
    for(int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

void vadd2(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
#ifdef __cilk
    _Cilk_for(int i = 0; i < n; i++)
#else
    #warning No Cilk support.  Using sequential for loop.
    for(int i = 0; i < n; i++)
#endif
        c[i] = a[i] + b[i];
}

void vadd3(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
#ifdef __cilk
    #if defined(__INTEL_COMPILER) && defined(__INTEL_OFFLOAD)
    #pragma offload target(gfx) in(a,b : length(n)) out(c : length(n)) //pin(a, b, c : length(n))
    #else
    #warning No Cilk offload support!
    #endif
    _Cilk_for(int i = 0; i < n; i++)
#else
    #warning No Cilk support.  Using sequential for loop.
    for(int i = 0; i < n; i++)
#endif
        c[i] = a[i] + b[i];
}

void vadd4(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
#if defined(_OPENMP) && (_OPENMP >= 201307)
    #pragma omp target map(to:n,a[0:n],b[0:n]) map(from:c[0:n])
    #pragma omp parallel for simd
#else
    #warning No OpenMP target/simd support!
    #pragma omp parallel for
#endif
    for(int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

#if USE_GFX

#include <gfx/gfx_rt.h>

__attribute__((target(gfx_kernel)))
void gfx_vadd5(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
    _Cilk_for(int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

void vadd5(int n, float * RESTRICT a, float * RESTRICT b, float * RESTRICT c)
{
    int rc = 0;
    rc = _GFX_share(a, sizeof(float)*n);
    if (rc) printf("_GFX_share returned %#06x\n", -_GFX_get_last_error());
    rc = _GFX_share(b, sizeof(float)*n);
    if (rc) printf("_GFX_share returned %#06x\n", -_GFX_get_last_error());
    rc = _GFX_share(c, sizeof(float)*n);
    if (rc) printf("_GFX_share returned %#06x\n", -_GFX_get_last_error());
    GfxTaskId id = _GFX_offload("gfx_vadd5", a, b, c, n);
    rc = _GFX_wait(id,1e9);
    if (rc) printf("_GFX_wait returned %#06x\n", -_GFX_get_last_error());
    rc = _GFX_unshare(a);
    if (rc) printf("_GFX_unshare returned %#06x\n", -_GFX_get_last_error());
    rc = _GFX_unshare(b);
    if (rc) printf("_GFX_unshare returned %#06x\n", -_GFX_get_last_error());
    rc = _GFX_unshare(c);
    if (rc) printf("_GFX_unshare returned %#06x\n", -_GFX_get_last_error());
}

#endif /* USE_GFX */

int main(int argc, char * argv[])
{
    int n = (argc > 1 ) ? atoi(argv[1]) : 1000;
    float * x  = calloc(n,sizeof(float)); assert(x !=NULL);
    float * y  = calloc(n,sizeof(float)); assert(y !=NULL);
    float * z0 = calloc(n,sizeof(float)); assert(z0!=NULL);
    float * z1 = calloc(n,sizeof(float)); assert(z1!=NULL);
    float * z2 = calloc(n,sizeof(float)); assert(z2!=NULL);
    float * z3 = calloc(n,sizeof(float)); assert(z3!=NULL);
    float * z4 = calloc(n,sizeof(float)); assert(z4!=NULL);
#if USE_GFX
    float * z5 = calloc(n,sizeof(float)); assert(z5!=NULL);
{'fraction_non_alphanumeric': 0.17922272047832585, 'fraction_numerical': 0.018535127055306428, 'mean_word_length': 3.3933026920551543, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7558304', 'n_tokens_mistral': 2924, 'n_tokens_neox': 2827, 'n_words': 730}