Skip to content

Commit eb84175

Browse files
committed
Merge branch 'devel'
2 parents 5cd1e77 + dbdaab1 commit eb84175

File tree

130 files changed

+546
-14095
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+546
-14095
lines changed

CMakeLists.txt

-21
This file was deleted.

CMakeModules/build_lua.cmake

-76
This file was deleted.

CMakeModules/lua_MSVC.patch

-21
This file was deleted.

README.md

+25-62
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,32 @@
22

33
[ArrayFire](https://github.com/arrayfire/arrayfire) is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific computing code that is portable across CUDA, OpenCL and CPU devices. This project provides Lua bindings for the ArrayFire library.
44

5-
The wrapper is currently compliant with ArrayFire 3.2 API (and higher). If you find any bugs, please report them [here](https://github.com/arrayfire/arrayfire-lua/issues).
5+
The wrapper is currently compliant with ArrayFire 3.4 API (and higher). If you find any bugs, please report them [here](https://github.com/arrayfire/arrayfire-lua/issues).
66

77
## Example
88

9-
```lua
10-
local AF = require("arrayfire")
9+
Sample code:
1110

12-
AF.main(function()
13-
local x = AF.randu(5, "f32")
14-
AF.print("x", x)
15-
AF.print("min of x", AF.min(x))
16-
AF.print("max of x", AF.max(x))
17-
end)
1811
```
12+
local af = require('arrayfire')
13+
af.info()
14+
a = af.Array{1, 2, 3, 4}
15+
af.print(a)
16+
```
17+
18+
Sample output:
1919

2020
```
21-
$ lua examples/lua/helloworld/intro.lua
22-
ArrayFire v3.2.1 (CUDA, 64-bit Linux, build f263db0)
23-
Platform: CUDA Toolkit 7.5, Driver: 358.16
24-
[0] GeForce GTX 690, 2047 MB, CUDA Compute 3.0
25-
-1- GeForce GTX 690, 2048 MB, CUDA Compute 3.0
26-
27-
x
28-
[5 1 1 1]
29-
0.7402
30-
0.9210
31-
0.0390
32-
0.9690
33-
0.9251
34-
35-
min of x
36-
[1 1 1 1]
37-
0.0390
38-
max of x
39-
[1 1 1 1]
40-
0.9690
21+
ArrayFire v3.5.0 (CUDA, 64-bit Linux, build 06e605b0)
22+
Platform: CUDA Toolkit 8, Driver: 378.13
23+
[0] GeForce GTX 950, 1996 MB, CUDA Compute 5.2
24+
25+
ArrayFire Array
26+
[4 1 1 1]
27+
1.0000
28+
2.0000
29+
3.0000
30+
4.0000
4131
4232
```
4333

@@ -49,8 +39,8 @@ TODO
4939

5040
### Requirements
5141

52-
- `cmake`
53-
- `Visual Studio` on Windows, `clang` / `gcc` on Linux / OSX.
42+
- [luarocks](https://github.com/keplerproject/luarocks)
43+
- [luaffi](https://github.com/facebook/luaffifb) (Not required for LuaJIT)
5444

5545
### Get ArrayFire libraries
5646

@@ -65,37 +55,10 @@ You can install ArrayFire using one of the following two ways.
6555

6656
### Building the Lua module
6757

68-
**Windows**
69-
70-
1. Launch `cmake-gui`. Set source and build directories.
71-
2. Press configure.
72-
3. Select `generator` as `Visual Studio 12 2013 Win64`.
73-
- You can choose a different generator as long as it is Win64.
74-
4. Set `CMAKE_INSTALL_PREFIX` to a location of choice.
75-
5. Press generate. The generated visual studio solution file will be present in the build directory.
76-
6. Open the VS solution file and build the `INSTALL` project.
77-
78-
**Linux / OSX**
79-
80-
1. Make sure the environment variable `ArrayFire_DIR` is set to `/path/to/arrayfire/share/ArrayFire/cmake`.
81-
2. Create a build directory and `cd` into it.
82-
3. Run `cmake /path/to/arrayfire-lua/ -DCMAKE_INSTALL_PREFIX=package`.
83-
4. Run `make`
84-
85-
### Setting up Lua paths
86-
87-
**Windows**
88-
89-
> SET LUA_PATH=C:\path\to\install\location\arrayfire\?.lua;;
90-
> SET LUA_CPATH=C:\path\to\install\location\?.dll;;
91-
> lua.exe helloworld/helloworld.lua
92-
93-
**Linux**
94-
95-
$ export LUA_PATH="/path/to/install/location/arrayfire/?.lua;;"
96-
$ export LUA_CPATH="/path/to/install/location/?.so;;"
97-
$ lua helloworld/helloworld.lua
98-
58+
```
59+
cd /path/to/arrayfire-lua/
60+
luarocks make
61+
```
9962

10063
You should now be good to go!
10164

arrayfire.lua

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require('arrayfire.lib')
2+
require('arrayfire.defines')
3+
require('arrayfire.util')
4+
require('arrayfire.array')
5+
require('arrayfire.device')
6+
7+
return af

arrayfire/array.lua

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
require('arrayfire.lib')
2+
require('arrayfire.defines')
3+
local ffi = require( "ffi" )
4+
5+
local funcs = {}
6+
funcs[30] = [[
7+
af_err af_create_array(af_array *arr, const void * const data,
8+
const unsigned ndims, const dim_t * const dims, const af_dtype type);
9+
10+
af_err af_create_handle(af_array *arr, const unsigned ndims,
11+
const dim_t * const dims, const af_dtype type);
12+
13+
af_err af_copy_array(af_array *arr, const af_array in);
14+
15+
af_err af_write_array(af_array arr, const void *data, const size_t bytes, af_source src);
16+
17+
af_err af_get_data_ptr(void *data, const af_array arr);
18+
19+
af_err af_release_array(af_array arr);
20+
21+
af_err af_retain_array(af_array *out, const af_array in);
22+
23+
af_err af_get_elements(dim_t *elems, const af_array arr);
24+
25+
af_err af_get_type(af_dtype *type, const af_array arr);
26+
af_err af_get_dims(dim_t *d0, dim_t *d1, dim_t *d2, dim_t *d3,
27+
const af_array arr);
28+
29+
af_err af_get_numdims(unsigned *result, const af_array arr);
30+
31+
af_err af_is_empty (bool *result, const af_array arr);
32+
33+
af_err af_is_scalar (bool *result, const af_array arr);
34+
35+
af_err af_is_row (bool *result, const af_array arr);
36+
af_err af_is_column (bool *result, const af_array arr);
37+
38+
af_err af_is_vector (bool *result, const af_array arr);
39+
af_err af_is_complex (bool *result, const af_array arr);
40+
41+
af_err af_is_real (bool *result, const af_array arr);
42+
af_err af_is_double (bool *result, const af_array arr);
43+
af_err af_is_single (bool *result, const af_array arr);
44+
af_err af_is_realfloating (bool *result, const af_array arr);
45+
af_err af_is_floating (bool *result, const af_array arr);
46+
af_err af_is_integer (bool *result, const af_array arr);
47+
af_err af_is_bool (bool *result, const af_array arr);
48+
af_err af_eval(af_array in);
49+
]]
50+
51+
funcs[31] = [[
52+
af_err af_get_data_ref_count(int *use_count, const af_array in);
53+
]]
54+
55+
56+
funcs[34] = [[
57+
af_err af_eval_multiple(const int num, af_array *arrays);
58+
af_err af_set_manual_eval_flag(bool flag);
59+
af_err af_get_manual_eval_flag(bool *flag);
60+
af_err af_is_sparse (bool *result, const af_array arr);
61+
]]
62+
63+
af.lib.cdef(funcs)
64+
65+
local Array = {}
66+
Array.__index = Array
67+
68+
local c_dim4_t = af.ffi.c_dim4_t
69+
local c_uint_t = af.ffi.c_uint_t
70+
local c_array_p = af.ffi.c_array_p
71+
72+
local add_finalizer = function(arr_ptr)
73+
return ffi.gc(arr_ptr[0], af.clib.af_release_array)
74+
end
75+
76+
Array.__init = function(data, dims, dtype, source)
77+
local self = setmetatable({}, Array)
78+
79+
if data then
80+
assert(af.istable(data))
81+
end
82+
83+
if dims then
84+
assert(af.istable(dims))
85+
end
86+
87+
c_dims = c_dim4_t(dims or (data and {#data} or {}))
88+
c_ndims = c_uint_t(dims and #dims or (data and 1 or 0))
89+
90+
nelement = 1
91+
for i = 1,tonumber(c_ndims) do
92+
nelement = nelement * c_dims[i - 1]
93+
end
94+
nelement = tonumber(nelement)
95+
96+
local atype = dtype or af.dtype.f32
97+
local res = c_array_p()
98+
if not data then
99+
af.clib.af_create_handle(res, c_ndims, c_dims, atype)
100+
else
101+
c_data = ffi.new(af.dtype_names[atype + 1] .. '[?]', nelement, data)
102+
af.clib.af_create_array(res, c_data, c_ndims, c_dims, atype)
103+
end
104+
self.__arr = add_finalizer(res)
105+
return self
106+
end
107+
108+
Array.__tostring = function(self)
109+
return 'arrayfire.Array\n'
110+
end
111+
112+
Array.get = function(self)
113+
return self.__arr
114+
end
115+
116+
setmetatable(
117+
Array,
118+
{
119+
__call = function(cls, ...)
120+
return cls.__init(...)
121+
end
122+
}
123+
)
124+
125+
af.Array = Array
126+
af.ffi.add_finalizer = add_finalizer

0 commit comments

Comments
 (0)