arrayfire / arrayfire-dotnet

.NET wrapper for ArrayFire
BSD 3-Clause "New" or "Revised" License
78 stars 21 forks source link

Basic Indexing Support #7

Closed royalstream closed 8 years ago

royalstream commented 8 years ago

Summary:

The HelloWorld examples have a few new lines showing the indexing functionality for both C# and F#

Array.cs: has a new indexing operator [] Util.cs: new Seq() and Span members Data.cs: new Copy() method (which was missing)

Inside the Interop folder there's a new file (AFIndex.cs) and there's a new class af_seq.

AutoGenTool changes can be pretty much ignored since they are only for development purposes (code/interop generation).

altaybrusan commented 8 years ago

Thank royalstream. It works cool. I also noticed another issue, before issuing a post I want to have your suggestion: is it possible to divide an array with a double?

One more time thanks for your contributions

royalstream commented 8 years ago

@altaybrusan you're welcome. I've found no way to scale an array by a scalar using the C API (which is what arrayfire-dotnet wraps) All the arithmetic operations are between two arrays. Looking at the C++ code for the *= and /= operators (when used with a scalar) it seems like internally what they do is creating a temporary constant array of the same size and then performing the operation as usual (see the ASSIGN_TYPE macro in their array.cpp). I could add this functionality as a separate PR (after they accept this one). But in the meantime you could do the same by hand.

altaybrusan commented 8 years ago

Ye,Thats what I have done

altaybrusan commented 8 years ago

I also noticed there is no function for loading files,such as af_load_image_memory available in the wrapper! Any idea if is going to be implemented near soon or not?

shehzan10 commented 8 years ago

I'm not sure if its just my system, but I'm running into a Backend Mismatch error for OpenCL (works fine for CUDA and CPU). I'm trying to investigate what the cause is.

The ArrayFire OpenCL examples work fine though.

Edit: It looks like its setting the CUDA Backend for OpenCL too. Backtrace:

Testing OPENCL Backend
ArrayFire v3.3.0 (CUDA, 64-bit Windows, build 5842ed2)
Platform: CUDA Toolkit 7.5, Driver: CUDA Driver Version: 8000
[0] GeForce GTX 770, 2048 MB, CUDA Compute 3.0
3
ArrayFire.ArrayFireException: 503
   at ArrayFire.Internal.VERIFY(af_err err) in d:\workspace\arrayfire-dotnet\Wrapper\Internal.cs:line 169
   at ArrayFire.Array.op_Addition(Array lhs, Array rhs) in d:\workspace\arrayfire-dotnet\Wrapper\Array.cs:line 143
   at CSharpTesting.Program.TestBackend() in d:\workspace\arrayfire-dotnet\Examples\Unified\CSharp\Program.cs:line 17
   at CSharpTesting.Program.Main(String[] args) in d:\workspace\arrayfire-dotnet\Examples\Unified\CSharp\Program.cs:line 47
shehzan10 commented 8 years ago

The helloworld C# example is running into vshost.exe has stopped working. Would you know anything about this?

royalstream commented 8 years ago

Quick question: If I'm using the Unified Backend, how could I be doing something wrong for OpenCL but right for CUDA? Could it be related to multiple OpenCL devices on the same machine? I remember that being an issue.

shehzan10 commented 8 years ago

Yeah I'm not entirely sure either. I tried looking at the code but found nothing obvious...im going to try and test it on another machine.

royalstream commented 8 years ago

Do you get the error if you run the OpenCL without running the CPU and CUDA tests? That is, please comment out the first two tests.

shehzan10 commented 8 years ago

Yes I tested OpenCL only, and that failed too. I tested the helloworld examples too by calling CPU/CUDA/OpenCL all independently. OpenCL still ran into the same error.

royalstream commented 8 years ago

In my computer it runs perfectly, as long as I only run OpenCL without CUDA or CPU before it and as long as I don't use DEBUGGING.

Are you using the code from my new PR or the previous version? I don't think this PR is related, both should behave in the same way.

shehzan10 commented 8 years ago

Here are further observations:

shehzan10 commented 8 years ago

Well, my bad I think my last point can be ignored.

royalstream commented 8 years ago

This is what I've found on my system:

Do you get the same behavior?

royalstream commented 8 years ago

Maybe we should continue this conversation here

royalstream commented 8 years ago

What about this PR? can it be merged?

shehzan10 commented 8 years ago

Can you make the changes to the helloworld example (use Backend.DEFAULT) and print device info? Also, the vshost.exe failure happens in debug mode. It looks like it may have to do with the build options.

Once these two action items are done, I'll merge it.

shehzan10 commented 8 years ago

The vshost one can be fixed by checking the Project Properties -> Debug -> Enable Native Code Debugging box in the C# and ArrayFire DLL projects.

royalstream commented 8 years ago

I had to edit the csproj by hand because using the checkbox was saving the changes in the csproj.user file. In any event, the changes are done.