Comments (4)
The problem is that char is defined differently in C# and OpenCL:
In C# char is 16 bit: https://docs.microsoft.com/en-us/dotnet/api/system.char?view=netframework-4.8
In OpenCL char is 8 bit: https://www.khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/scalarDataTypes.html
Your code works if you replace char by byte in the host part. After casting the byte array to char the output is correct.
from cloo.
Can you post some more code? From your example it seems that you are not executing your kernel, but only setting the argument. Also if you perform a non blocking read you will have to synchronize before checking the content of the host buffer.
from cloo.
Full Code
try
{
char[] pw_cracked = new char[5];
var kernelCl = File.ReadAllText("kernel.cl");
ComputePlatform platform = ComputePlatform.Platforms[0];
ComputeContextPropertyList properties = new ComputeContextPropertyList(platform);
ComputeContext context = new ComputeContext(platform.Devices, properties, null, IntPtr.Zero);
ComputeBuffer<char> cracked_pw_mem_obj = new ComputeBuffer<char>(context, ComputeMemoryFlags.WriteOnly | ComputeMemoryFlags.CopyHostPointer, pw_cracked);
ComputeProgram program = new ComputeProgram(context, kernelCl);
program.Build(null, null, null, IntPtr.Zero);
ComputeKernel kernel = program.CreateKernel("vector_add");
kernel.SetMemoryArgument(0, cracked_pw_mem_obj);
ComputeEventList eventList = new ComputeEventList();
ComputeCommandQueue commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);
commands.Execute(kernel, null, new long[] { GLOBAL_ITEM_SIZE }, new long[] { LOCAL_ITEM_SIZE }, eventList);
commands.ReadFromBuffer(cracked_pw_mem_obj, ref pw_cracked, false, eventList);
commands.Finish();
Console.WriteLine("Cracked Password: " + String.Join("", pw_cracked));
commands.Dispose();
foreach (ComputeEventBase eventBase in eventList)
{
eventBase.Dispose();
}
eventList.Clear();
kernel.Dispose();
program.Dispose();
cracked_pw_mem_obj.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
from cloo.
Yep! it was that :)
byte[] pw_cracked = new byte[maxlen + 1];
ComputeBuffer<byte> cracked_pw_mem_obj = new ComputeBuffer<byte>(context, ComputeMemoryFlags.WriteOnly | ComputeMemoryFlags.CopyHostPointer, pw_cracked);
Console.WriteLine("Cracked Password: " + String.Join("", pw_cracked.Select( p => Convert.ToChar(p))));
from cloo.
Related Issues (11)
- Logging Kernel Errors? HOT 1
- Can I create one ComputeBuffer, repeatedly set data in it? HOT 4
- Cannot find or open the PDB file HOT 1
- CreateImage2D obsolete/deprecated? HOT 1
- is any way to debug the kernel code in VS? HOT 2
- VectorAddExample doesn't work for AMD GPU HOT 1
- macOS support
- ComputeBuffer data array improperly pinned HOT 5
- How to set global variables not included in kernel? HOT 1
- Bool type maybe wrong calculated HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloo.