File: test_sum.c

package info (click to toggle)
haskell-futhark 0.25.32-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,236 kB
  • sloc: haskell: 100,484; ansic: 12,100; python: 3,440; yacc: 785; sh: 561; javascript: 558; lisp: 399; makefile: 277
file content (63 lines) | stat: -rw-r--r-- 1,727 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "sum.h"
#include <assert.h>
#include <string.h>
#include <stdlib.h>

int main() {
  int rounds = 10;

  struct futhark_context_config *cfg = futhark_context_config_new();
  struct futhark_context *ctx = futhark_context_new(cfg);

  struct futhark_opaque_contrived* v;
  {
    int32_t data[] = { 1, 2, 3 };
    struct futhark_i32_1d* arr = futhark_new_i32_1d(ctx, data, sizeof(data)/sizeof(int32_t));
    assert(arr != NULL);
    assert(futhark_context_sync(ctx) == FUTHARK_SUCCESS);
    assert(futhark_new_opaque_contrived_foo(ctx, &v, arr, true) == FUTHARK_SUCCESS);
    futhark_free_i32_1d(ctx, arr);
  }

  for (int i = 0; i < rounds; i++) {

    switch (futhark_variant_opaque_contrived(ctx, v)) {
    case 0:
      {
        bool v0;
        struct futhark_u32_1d *v1;
        futhark_destruct_opaque_contrived_bar(ctx, &v0, &v1, v);
        futhark_free_u32_1d(ctx, v1);
      }
      break;
    case 1:
      {
        struct futhark_i32_1d *v0;
        struct futhark_i32_1d *v1;
        futhark_destruct_opaque_contrived_baz(ctx, &v0, &v1, v);
        futhark_free_i32_1d(ctx, v0);
        futhark_free_i32_1d(ctx, v1);
      }
      break;
    case 2:
      {
        struct futhark_i32_1d *v0;
        bool v1;
        futhark_destruct_opaque_contrived_foo(ctx, &v0, &v1, v);
        futhark_free_i32_1d(ctx, v0);
      }
      break;
    default:
      abort();
    };

    struct futhark_opaque_contrived* v_new;
    assert(futhark_entry_next(ctx, &v_new, v) == FUTHARK_SUCCESS);
    assert(futhark_free_opaque_contrived(ctx, v) == FUTHARK_SUCCESS);
    v = v_new;
  }

  assert(futhark_free_opaque_contrived(ctx, v) == FUTHARK_SUCCESS);
  futhark_context_free(ctx);
  futhark_context_config_free(cfg);
}