Go to the documentation of this file.00001 #pragma once
00002
00003 #include <iomanip>
00004 #include <CL/cl.h>
00005 #include <string.h>
00006 #include <stdio.h>
00007 #include <iostream>
00008 #include <stdlib.h>
00009
00010
00011
00012 #if defined(_WIN32) || defined(_MSC_VER)
00013 #include <windows.h>
00014 #elif defined(__APPLE__) && defined(__MACH__)
00015
00016 #include <mach/mach_time.h>
00017 #else // Linux
00018 #include <sys/time.h>
00019 #endif
00020 #include <math.h>
00021
00069 #define MAX_PLATFORMS 16
00070 #define MAX_DEVICES 16
00071
00072 extern cl_context g_ctx;
00073 extern cl_command_queue g_queue;
00074 extern cl_program g_program;
00075 extern cl_device_id devices[MAX_DEVICES];
00076 extern int device_count;
00077 extern int current_device;
00078
00079 namespace af {
00080
00260
00261 typedef enum {
00262 AF_SINGLE_REAL,
00263 AF_SINGLE_CPLX
00264 } af_type;
00265
00266
00271
00272 typedef enum {
00273 af_valid = -1,
00274 af_same,
00275 af_full
00276 }af_mode;
00279
00281 typedef cl_float2 clFloatComplex;
00282
00283 class array {
00284
00285 public:
00286
00287
00288 int m_rows, m_cols;
00289 cl_mem m_obj;
00290 af_type type;
00291
00292
00301
00302 array(int rows, int cols=1, af_type type=AF_SINGLE_REAL);
00304 array();
00306 ~array();
00307
00310
00319 array(const float *src, int rows, int cols=1);
00320 array(const clFloatComplex *src, int rows, int cols=1);
00323
00331 array(const array&);
00332 array operator =(const array& in);
00335
00341
00342 void *host() const;
00344 cl_mem device() const { return m_obj; }
00347
00348
00354
00355 array T();
00357 array H();
00360
00365
00366 array conjugate();
00369
00370
00371 #define OP(op) \
00372 \
00373 array operator op(const array &lhs); \
00374 \
00375 friend array operator op(const float& lhs, array &rhs); \
00376 \
00377 array operator op(const float &lhs); \
00378 \
00379 array operator op(const clFloatComplex& lhs)
00380
00381 #define OP_COM(op) \
00382 \
00383 array operator op(const array &lhs); \
00384 \
00385 friend array operator op(const float& lhs, array &rhs) \
00386 { return rhs op lhs;} \
00387 \
00388 array operator op(const float &lhs); \
00389 \
00390 array operator op(const clFloatComplex& lhs)
00391
00397 OP_COM(+);
00398 OP_COM(*);
00399 OP(>);
00400 OP(-);
00401 OP(/);
00402
00403 array operator-();
00406
00407 #undef OP
00408 #undef OP_COM
00409 };
00410
00420 array setdims(const array &in, unsigned R, unsigned C);
00423
00424
00430
00431 void print_(const array& in);
00433 #define print(exp) do { std::cout << #exp << " =\n"; print_(exp); } while (0)
00434
00435 std::ostream& operator<<(std::ostream& out, const array in);
00438
00447
00448 array multiply(const array& A, const array& B);
00450 array dot(const array& A, const array& B);
00453
00462
00463 array fft1D(const array& in);
00465 array ifft1D(const array& in);
00467 array fft2D(const array& in);
00469 array ifft2D(const array& in);
00472
00481
00482 array convolve(const array& input, const array& filter, af_mode mode=af_full);
00485
00486
00492
00493 array real(const array& in);
00495 array imag(const array& in);
00497 array complex(const array& real, const array& imag);
00499 array complex(const array& real);
00501 array conjugate(const array& a);
00504
00505
00506
00507
00508
00513
00514 void info();
00517
00523
00524 void device(int dev);
00526 int device(void);
00529
00535
00536 void sync();
00539
00549
00550 array tile(array& in, int M, int N=1);
00553
00554
00555
00556 #define UNARY(OP) array OP(const array& in)
00557
00563 UNARY(sin);
00564 UNARY(cos);
00565 UNARY(tan);
00566 UNARY(asin);
00567 UNARY(acos);
00568 UNARY(atan);
00569
00572
00578 UNARY(erf);
00579 UNARY(exp);
00580 UNARY(sqrt);
00581 UNARY(log);
00584 #undef UNARY
00585
00587 typedef struct timer {
00588 #if defined(_WIN32) || defined(_MSC_VER)
00589 LARGE_INTEGER val;
00590 #elif defined(__APPLE__) && defined(__MACH__)
00591 uint64_t val;
00592 #else // Linux
00593 struct timeval val;
00594 #endif
00595
00597 static timer start();
00598
00600 static double stop();
00601
00603 static double stop(timer start);
00604
00605 } timer;
00606
00607 double timeit(void(*fn)());
00608
00609 }