File: test_raw.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 (37 lines) | stat: -rw-r--r-- 871 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
// Fiddling around with the raw arrays API.

#include "raw.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

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

#ifdef FUTHARK_BACKEND_c

  int32_t data[3] = {1,2,3};

  struct futhark_i32_1d *in = futhark_new_raw_i32_1d(ctx, (unsigned char*)&data, 3);
  assert(in != NULL);
  struct futhark_i32_1d *out;

  assert(futhark_entry_main(ctx, &out, in) == FUTHARK_SUCCESS);

  int32_t *out_ptr = (int32_t*)futhark_values_raw_i32_1d(ctx, out);

  assert(futhark_context_sync(ctx) == FUTHARK_SUCCESS);

  assert(out_ptr[0] == 3);
  assert(out_ptr[1] == 4);
  assert(out_ptr[2] == 5);

  futhark_free_i32_1d(ctx, in);
  futhark_free_i32_1d(ctx, out);

#endif

  futhark_context_free(ctx);
  futhark_context_config_free(cfg);
}