tests: fix build on os/x
[schroedinger.git] / schroedinger / schrocuda.c
blobf0386f066c11e359128fb8da96f4e44b3c07b30a
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
6 #include <schroedinger/schro.h>
7 #include <cuda_runtime_api.h>
9 #include <schroedinger/schrogpuframe.h>
10 #include <schroedinger/schrogpumotion.h>
12 void
13 schro_cuda_init (void)
15 int n;
16 int i;
17 cudaError_t ret;
19 ret = cudaGetDeviceCount (&n);
20 SCHRO_DEBUG ("cudaGetDeviceCount returned %d", ret);
22 SCHRO_DEBUG ("CUDA devices %d", n);
24 for (i = 0; i < n; i++) {
25 struct cudaDeviceProp prop;
27 cudaGetDeviceProperties (&prop, i);
28 SCHRO_DEBUG ("CUDA props: %d: %d.%d mem=%d %s", i,
29 prop.major, prop.minor, prop.totalGlobalMem, prop.name);
34 static void *
35 schro_cuda_alloc (int size)
37 void *ptr;
38 int ret;
40 SCHRO_DEBUG ("domain is %d", schro_async_get_exec_domain ());
41 //SCHRO_ASSERT(schro_async_get_exec_domain () == SCHRO_EXEC_DOMAIN_CUDA);
43 ret = cudaMalloc (&ptr, size);
45 return ptr;
48 static void
49 schro_cuda_free (void *ptr, int size)
51 //SCHRO_ASSERT(schro_async_get_exec_domain () == SCHRO_EXEC_DOMAIN_CUDA);
53 if (schro_async_get_exec_domain () == SCHRO_EXEC_DOMAIN_CUDA) {
54 cudaFree (ptr);
55 } else {
56 SCHRO_ERROR ("Freeing CUDA memory outside CUDA thread.");
60 SchroMemoryDomain *
61 schro_memory_domain_new_cuda (void)
63 SchroMemoryDomain *domain;
65 domain = schro_memory_domain_new ();
66 domain->flags = SCHRO_MEMORY_DOMAIN_CUDA;
67 domain->alloc = schro_cuda_alloc;
68 domain->free = schro_cuda_free;
70 return domain;
74 void
75 schro_motion_render_cuda (SchroMotion * motion, SchroFrame * dest)
77 SchroGPUMotion *gpumotion;
79 gpumotion = schro_gpumotion_new (0);
81 schro_gpumotion_init (gpumotion, motion);
83 schro_gpumotion_copy (gpumotion, motion);
84 schro_gpumotion_render (gpumotion, motion, dest);
86 schro_gpumotion_free (gpumotion);
89 void
90 schro_frame_inverse_iwt_transform_cuda (SchroFrame * frame,
91 SchroFrame * transform_frame, SchroParams * params)
93 schro_frame_to_gpu (frame, transform_frame);
95 schro_gpuframe_inverse_iwt_transform (frame, params);