Bug fixing in chroma block matching
[schroedinger/research-port.git] / testsuite / cuda / cuda.c
blob83eadb7708eb8d8be140ad5e386ffaa9a3af20e3
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
6 #include <schroedinger/schro.h>
7 #include <schroedinger/schromotion.h>
8 #include <schroedinger/schrodebug.h>
9 #include <schroedinger/schroutils.h>
10 #include <schroedinger/schrooil.h>
11 #include <schroedinger/schrocuda.h>
12 #include <schroedinger/schrogpuframe.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <math.h>
17 #include <liboil/liboilrandom.h>
18 #include <liboil/liboil.h>
20 #include "common.h"
22 void upsample_line (uint8_t *dest, int dstr, uint8_t *src, int sstr, int n);
23 void ref_h_upsample (SchroFrame *dest, SchroFrame *src);
24 void ref_v_upsample (SchroFrame *dest, SchroFrame *src);
26 void test (int width, int height);
28 int failed = 0;
30 int dump_all = FALSE;
32 SchroMemoryDomain *cpu_domain;
33 SchroMemoryDomain *cuda_domain;
35 int
36 main (int argc, char *argv[])
38 //int width, height;
40 schro_init();
42 cpu_domain = schro_memory_domain_new_local ();
43 cuda_domain = schro_memory_domain_new_cuda ();
45 #if 0
46 for(width=1;width<=20;width++){
47 for(height=1;height<=20;height++){
48 test (width, height);
51 #endif
52 test (640, 480);
54 if (failed) {
55 printf("FAILED\n");
56 } else {
57 printf("SUCCESS\n");
60 return failed;
63 void test (int width, int height)
65 SchroFrame *frame_u8;
66 SchroFrame *frame;
67 SchroFrame *frame_ref;
68 SchroFrame *frame_test;
69 SchroFrame *frame_cuda;
70 SchroParams params;
71 char name[TEST_PATTERN_NAME_SIZE];
72 int i;
73 int ok;
75 params.iwt_luma_width = width;
76 params.iwt_luma_height = height;
77 params.iwt_chroma_width = width/2;
78 params.iwt_chroma_height = height/2;
79 params.transform_depth = 1;
81 frame_u8 = schro_frame_new_and_alloc (cpu_domain,
82 SCHRO_FRAME_FORMAT_U8_420, width, height);
83 frame = schro_frame_new_and_alloc (cpu_domain,
84 SCHRO_FRAME_FORMAT_S16_420, width, height);
85 frame_cuda = schro_frame_new_and_alloc (cuda_domain,
86 SCHRO_FRAME_FORMAT_S16_420, width, height);
87 frame_ref = schro_frame_new_and_alloc (cpu_domain,
88 SCHRO_FRAME_FORMAT_S16_420, width, height);
89 frame_test = schro_frame_new_and_alloc (cpu_domain,
90 SCHRO_FRAME_FORMAT_S16_420, width, height);
92 for(i=0;i<test_pattern_get_n_generators();i++){
93 test_pattern_generate (frame_u8->components + 0, name, i);
94 test_pattern_generate (frame_u8->components + 1, name, i);
95 test_pattern_generate (frame_u8->components + 2, name, i);
96 schro_frame_convert (frame, frame_u8);
98 schro_frame_convert (frame_ref, frame_u8);
99 schro_frame_inverse_iwt_transform (frame_ref, &params);
101 schro_frame_to_gpu (frame_cuda, frame);
102 schro_gpuframe_inverse_iwt_transform (frame_cuda, &params);
103 schro_gpuframe_to_cpu (frame_test, frame_cuda);
105 ok = frame_compare (frame_ref, frame_test);
106 printf(" pattern %s: %s\n", name, ok ? "OK" : "broken");
107 if (dump_all || !ok) {
108 frame_data_dump_full (frame_test->components + 0,
109 frame_ref->components + 0, frame->components + 0);
110 failed = TRUE;
114 schro_frame_unref (frame);
115 schro_frame_unref (frame_ref);
116 schro_frame_unref (frame_test);
117 schro_frame_unref (frame_cuda);