Skip to content

Commit 89b6eb8

Browse files
committed
Initial commit
0 parents  commit 89b6eb8

File tree

11 files changed

+317
-0
lines changed

11 files changed

+317
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist*
2+
result/

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for fire
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.

LICENSE

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2018, David Johnson
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of David Johnson nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Main.hs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Main where
2+
3+
import Data.Array.Fire
4+
5+
main = undefined -- print F32

Setup.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

default.nix

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{ pkgs ? import <nixpkgs> {} }:
2+
pkgs.haskellPackages.callPackage ./pkg.nix {}

fire.cabal

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: fire
2+
version: 0.1.0.0
3+
synopsis: Haskell bindings to ArrayFire
4+
description: High-level Haskell bindings to ArrayFire
5+
homepage: https://github.com/dmjio/fire
6+
license: BSD3
7+
license-file: LICENSE
8+
author: David Johnson
9+
maintainer: djohnson.m@gmail.com
10+
copyright: David Johnson (c) 2018-2020
11+
category: Math
12+
build-type: Simple
13+
extra-source-files: CHANGELOG.md
14+
cabal-version: >=1.10
15+
16+
library
17+
exposed-modules:
18+
Data.Array.Fire
19+
build-tools:
20+
hsc2hs
21+
include-dirs:
22+
include
23+
build-depends:
24+
base < 5
25+
hs-source-dirs:
26+
src
27+
default-language:
28+
Haskell2010
29+
30+
executable main
31+
main-is:
32+
Main.hs
33+
build-depends:
34+
base < 5, fire
35+
default-language:
36+
Haskell2010

include/fire.h

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#define AF_API_VERSION 1.0
2+
3+
typedef enum {
4+
f32, ///< 32-bit floating point values
5+
c32, ///< 32-bit complex floating point values
6+
f64, ///< 64-bit complex floating point values
7+
c64, ///< 64-bit complex floating point values
8+
b8 , ///< 8-bit boolean values
9+
s32, ///< 32-bit signed integral values
10+
u32, ///< 32-bit unsigned integral values
11+
u8 , ///< 8-bit unsigned integral values
12+
s64, ///< 64-bit signed integral values
13+
u64, ///< 64-bit unsigned integral values
14+
s16, ///< 16-bit signed integral values
15+
u16, ///< 16-bit unsigned integral values
16+
} af_dtype;
17+
18+
typedef enum {
19+
///
20+
/// The function returned successfully
21+
///
22+
AF_SUCCESS = 0,
23+
24+
// 100-199 Errors in environment
25+
26+
///
27+
/// The system or device ran out of memory
28+
///
29+
AF_ERR_NO_MEM = 101,
30+
31+
///
32+
/// There was an error in the device driver
33+
///
34+
AF_ERR_DRIVER = 102,
35+
36+
///
37+
/// There was an error with the runtime environment
38+
///
39+
AF_ERR_RUNTIME = 103,
40+
41+
// 200-299 Errors in input parameters
42+
43+
///
44+
/// The input array is not a valid af_array object
45+
///
46+
AF_ERR_INVALID_ARRAY = 201,
47+
48+
///
49+
/// One of the function arguments is incorrect
50+
///
51+
AF_ERR_ARG = 202,
52+
53+
///
54+
/// The size is incorrect
55+
///
56+
AF_ERR_SIZE = 203,
57+
58+
///
59+
/// The type is not suppported by this function
60+
///
61+
AF_ERR_TYPE = 204,
62+
63+
///
64+
/// The type of the input arrays are not compatible
65+
///
66+
AF_ERR_DIFF_TYPE = 205,
67+
68+
///
69+
/// Function does not support GFOR / batch mode
70+
///
71+
AF_ERR_BATCH = 207,
72+
73+
///
74+
/// Input does not belong to the current device.
75+
///
76+
AF_ERR_DEVICE = 208,
77+
78+
// 300-399 Errors for missing software features
79+
80+
///
81+
/// The option is not supported
82+
///
83+
AF_ERR_NOT_SUPPORTED = 301,
84+
85+
///
86+
/// This build of ArrayFire does not support this feature
87+
///
88+
AF_ERR_NOT_CONFIGURED = 302,
89+
90+
///
91+
/// This build of ArrayFire is not compiled with "nonfree" algorithms
92+
///
93+
AF_ERR_NONFREE = 303,
94+
95+
// 400-499 Errors for missing hardware features
96+
97+
///
98+
/// This device does not support double
99+
///
100+
AF_ERR_NO_DBL = 401,
101+
102+
///
103+
/// This build of ArrayFire was not built with graphics or this device does
104+
/// not support graphics
105+
///
106+
AF_ERR_NO_GFX = 402,
107+
108+
// 500-599 Errors specific to heterogenous API
109+
110+
///
111+
/// There was an error when loading the libraries
112+
///
113+
AF_ERR_LOAD_LIB = 501,
114+
115+
///
116+
/// There was an error when loading the symbols
117+
///
118+
AF_ERR_LOAD_SYM = 502,
119+
120+
///
121+
/// There was a mismatch between the input array and the active backend
122+
///
123+
AF_ERR_ARR_BKND_MISMATCH = 503,
124+
125+
// 900-999 Errors from upstream libraries and runtimes
126+
127+
///
128+
/// There was an internal error either in ArrayFire or in a project
129+
/// upstream
130+
///
131+
AF_ERR_INTERNAL = 998,
132+
133+
///
134+
/// Unknown Error
135+
///
136+
AF_ERR_UNKNOWN = 999
137+
} af_err;

pkg.nix

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{ mkDerivation, base, stdenv }:
2+
mkDerivation {
3+
pname = "fire";
4+
version = "0.1.0.0";
5+
src = ./.;
6+
libraryHaskellDepends = [ base ];
7+
homepage = "https://github.com/dmjio/fire";
8+
description = "Haskell bindings to ArrayFire";
9+
license = stdenv.lib.licenses.bsd3;
10+
}

src/Data/Array/Fire.hsc

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{-# LANGUAGE CPP #-}
2+
module Data.Array.Fire where
3+
4+
import Foreign
5+
import Foreign.C.Types
6+
7+
#include "fire.h"
8+
9+
afVersion = #const AF_API_VERSION
10+
11+
newtype AFDType = AFDType { afDType :: Int }
12+
deriving (Show, Eq)
13+
14+
#{enum AFDType, AFDType
15+
, f32 = f32
16+
, c32 = c32
17+
, f64 = f64
18+
, c64 = c64
19+
, b8 = b8
20+
, s32 = s32
21+
, u32 = u32
22+
, u8 = u8
23+
, s64 = s64
24+
, u64 = u64
25+
, s16 = s16
26+
, u16 = u16
27+
}
28+
29+
newtype AFError = AFError { afError :: Int }
30+
deriving (Show, Eq)
31+
32+
#{enum AFError, AFError
33+
, afSuccess = AF_SUCCESS
34+
, afErrNoMem = AF_ERR_NO_MEM
35+
, afErrDriver = AF_ERR_DRIVER
36+
}
37+
38+
newtype AFArray = AFArray (ForeignPtr AFArray)

src/Data/Array/Fire_hsc_make.c

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "/nix/store/r9rkkv42lhi2p2ywlsi40g07m1x1ypzc-ghc-8.6.1/lib/ghc-8.6.1/template-hsc.h"
2+
#line 7 "Fire.hsc"
3+
#include "fire.h"
4+
5+
int main (void)
6+
{
7+
hsc_line (1, "src/Data/Array/Fire.hsc");
8+
hsc_fputs ("", hsc_stdout());
9+
hsc_fputs ("{-# LANGUAGE CPP #-}\n"
10+
"", hsc_stdout());
11+
hsc_fputs ("module Data.Array.Fire where\n"
12+
"\n"
13+
"import Foreign\n"
14+
"import Foreign.C.Types\n"
15+
"\n"
16+
"", hsc_stdout());
17+
hsc_fputs ("\n"
18+
"", hsc_stdout());
19+
hsc_fputs ("\n"
20+
"afVersion = ", hsc_stdout());
21+
#line 9 "Fire.hsc"
22+
hsc_const (AF_API_VERSION);
23+
hsc_fputs ("\n"
24+
"", hsc_stdout());
25+
hsc_line (10, "src/Data/Array/Fire.hsc");
26+
hsc_fputs ("\n"
27+
"-- data DType\n"
28+
"-- = F32\n"
29+
"-- | C32\n"
30+
"-- | F64\n"
31+
"-- | C64\n"
32+
"-- | B8\n"
33+
"-- | S32\n"
34+
"-- | U32\n"
35+
"-- | U8\n"
36+
"-- | S64\n"
37+
"-- | U64\n"
38+
"-- | S16\n"
39+
"-- | U16\n"
40+
"-- deriving (Show)\n"
41+
"\n"
42+
"{ ", hsc_stdout());
43+
#line 26 "Fire.hsc"
44+
hsc_fputs ("", hsc_stdout());
45+
hsc_fputs ("}\n"
46+
"", hsc_stdout());
47+
hsc_line (27, "src/Data/Array/Fire.hsc");
48+
hsc_fputs ("", hsc_stdout());
49+
return 0;
50+
}

0 commit comments

Comments
 (0)