Log in

View Full Version : running the CPU and GPU on a Raspberry pi.(Searching..) and I ran across this.


BanMe_2
December 28th, 2014, 20:32
In the spirit of leaving a trail of breadcrumbs through the forest, I�m going to run through some of what I learned along the way.

http://petewarden.com/2014/08/07/how-to-optimize-raspberry-pi-code-using-its-gpu/

Excellent article and has links to even more interesting documentation for the pi.

As a side note or tip for running mono C# code on raspberry pi.
Code:

static Object FileLock = new Object();
static void Main()
{
//Get the Directory This is executing from example "WorkFolder\XmlData\..."
System.IO.DirectoryInfo workingDirectory = new System.IO.DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
//## requirement of being in the directory where the xml files to be parsed are.##
//read all the ProductData*.xml files in the current directory
System.IO.FileInfo[] xmlFiles = workingDirectory.GetFiles("ProductData*.xml";
//Create A thread Array equal to the number of files to parse
//Create a thread for each file found to parse in parallel
for (int i = 0; i < xmlFiles.Length - 1; i++) {
System.Threading.Thread T = new System.Threading.Thread(() => thread_parser(xmlFiles[I].FullName));
T.Start();
}
}


This will not work if the number of files and there sizes exceeds the memory Threshold of the device.
There are a few ways to accomplish this.
Use a global counter and to only allow a certain number of threads to be running in the code.
Remove the threading part all together and go for a function loop on thread_parser.
Implement a lock in thread_parser to only allow 1 thread.

Kayaker
January 5th, 2015, 18:46
Still reversing that esoteric stuff huh? Good on ya, keep it up
Sorry, we still haven't banned you after all these years

BanMe_2
January 8th, 2015, 13:31
Nah, just got a pi for Christmas and jumped into what I thought was interesting in the community and wanted to see if I could write code to run on the GPU of the pi.

The code is the head of the implementation to parse GS1 1worldsync product data from manufacturers into NCR Power Menu for a distributor.(boring shit right there..)

Towards the last comment:
Self made shackles work best for me, breaking out of them is really hard and time consuming unlike anything you or others could have done to me.

This is supposed to be off-topic so I should have avoided your question and just rambled on..

Woodmann
January 9th, 2015, 20:50
I dont see any way I could ban him.

Anyway, interesting stuff regarding pi.

Woodmann

BanMe_2
January 30th, 2015, 12:29
https://www.khronos.org/opengles/sdk/docs/reference_cards/OpenGL-ES-2_0-Reference-card.pdf
https://www.khronos.org/opengles/2_X/

http://nullprogram.com/ more in depth usage examples
https://news.ycombinator.com/item?id=1460065
http://learningwebgl.com/blog/?p=1828


Enjoy the reading, any further information or usage experimentation notes would be greatly appreciated if a link was posted here.

BanMe_2
January 30th, 2015, 12:56
So taking a idea from stenography and encoding 1 picture inside another using the least significant byte of a pixels RGB...So this is all well and good when combining 2 images, but what if I don't want to embed a image into another image. what if I want to embed Ascii into a image. I suppose the same method would work, read a the image data for RGBA, find the least significant byte and overwrite it with desired code for 1 value. But what if we don't care who see's my modifications to the image, this opens up RGB for storage in the full scale. To accomplish this I take image and load it into a canvas with image.width - 2 and image.height -2 to allow for a 1 pixel border region for data. I then directly associated ascii keycodes to color codes and write the desired text to the image. 1 of the most annoying things I ran across while implementing this functionality was CORS(cross origin resource sharing policy) and SORS(Same origin resource sharing Policy) which describe a set of permissions for editing and modifying content downloaded from the web.It seems chrome chokes on this much more then even IE, firefox or opera.

The next stage of this is taking the 2d data fragments and storing them into a 3D cylinders inner surface with multiple viewpoints set onto a line that runs up the middle of the cylinder. IE each viewpoint has a range of accessible data located next to that view point to which I can send a query to retrieve the data in question via reducing the overall space the query has to look through.

Kayaker
January 30th, 2015, 23:25
If you're into transmogrifying files, you might be interested or already seen some of these examples of binary polyglots.

https://code.google.com/p/corkami/ (under Binary Files)

A few of the polyglots are actual issues of the International Journal of Proof-of-Concept or Get The Fuck Out (PoC||GTFO)
(google 'pocgtfo' for some analysis of how to manipulate the file contents)

Issue 03 is, at the same time, several file formats: PDF/ZIP/JPG/Audio (raw AFSK)/PNG (encrypted with AES)
Issue 04: TrueCrypt, PDF , ZIP polyglots
Issue 05: Flash, Iso, PDF, ZIP polyglots

Pretty amazing stuff. I found that Foxit might open the pdf format if Adobe doesn't, and 7-zip or or 'nix unzip could handle it when the extension is changed to .zip.

Would be interested in seeing your ascii-in-jpg if you get a poc.

K.

BanMe_2
February 1st, 2015, 19:43
Code is written in Javascript, and I have posted it to codereview.stackexchange.com a few times to get idea's on improvements for my code.

Code:

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="200" height="200" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<p id="Start"></p>
<p id="End"></p>
<div id="img_store" style="display:none"></div>
<textarea id="WriteThis"></textarea>
<button onclick="loadImageAndWrite('download.png');">Load Image and Write Text</button>
<script>
var ColorizeData = function(canvas) {
this.canvas = canvas;
this.charToDecTable = {};
this.decToCharTable = {};
}
ColorizeData.prototype.initTables = function(){
var charDecPairs = [
[" ","09"],
["\r","16"],
["\n","19"],
[" ","32"],
["!","33"],
['"',"34"],
["#","35"],
["$","36"],
["%","37"],
["&","38"],
["'","39"],
["(","40"],
["","41"],
["*","42"],
["+","43"],
[",","44"],
["-","45"],
[".","46"],
["/","47"],
["0","48"],
["1","49"],
["2","50"],
["3","51"],
["4","52"],
["5","53"],
["6","54"],
["7","55"],
["8","56"],
["9","57"],
[":","58"],
[";","59"],
["<","60"],
["=","61"],
[">","62"],
["?","63"],
["@","64"],
["A","65"],
["B","66"],
["C","67"],
["D","68"],
["E","69"],
["F","70"],
["G","71"],
["H","72"],
["I","73"],
["J","74"],
["K","75"],
["L","76"],
["M","77"],
["N","78"],
["O","79"],
["P","80"],
["Q","81"],
["R","82"],
["S","83"],
["T","84"],
["U","85"],
["V","86"],
["W","87"],
["X","88"],
["Y","89"],
["Z","90"],
["[","91"],
["\\","92"],
["]","93"],
["^","94"],
["_","95"],
["`","96"],
["a","97"],
["b","98"],
["c","99"],
["d","100"],
["e","101"],
["f","102"],
["g","103"],
["h","104"],
["i","105"],
["j","106"],
["k","107"],
["l","108"],
["m","109"],
["n","110"],
["o","111"],
["p","112"],
["q","113"],
["r","114"],
["s","115"],
["t","116"],
["u","117"],
["v","118"],
["w","119"],
["x","120"],
["y","121"],
["z","122"],
["{","123"],
["|","124"],
["}","125"],
["~","126"],
["","127"]


];
for(i=0; i < charDecPairs.length; i++)
{
var pair = charDecPairs[I];
var cchar = pair[0];
var dec = pair[1];
this.charToDecTable[cchar] = dec;
this.decToCharTable[hex] = cchar;
}
}
ColorizeData.prototype.textToColor = function(arg){
var context = this.canvas.getContext("2d";
var upDown = 1;
var upDown1 = 1;
var leftRight = 0;
var cindex = 0;
arg = arg.toLowerCase();
do
{
if(cindex + 1 < arg.length)
{
if(cindex + 2 < arg.length)
{
context.fillStyle = rgbToHex(this.charToDecTable[arg.charAt(cindex)],this.charToDecTable[arg.charAt(cindex+1)],this.charToDecTable[arg.charAt(cindex+2)]);
cindex += 3;
}
else
{
context.fillStyle = rgbToHex(this.charToDecTable[prop], this.charToDecTable[arg.charAt(cindex+1)],0);
cindex += 2;
}
}
else
{
context.fillStyle = rgbToHex(this.charToDecTable[prop],0, 0);
cindex +=1;
}
if(context.fillStyle != "#000000"
{

if(cindex/3 < this.canvas.width) {
context.fillRect(leftRight, 0, 1, 1);
leftRight += 1;
}
else
{
if(upDown < this.canvas.height) {
context.fillRect(leftRight,upDown,1,1);
upDown += 1;
}
else
{
if(upDown1 < this.canvas.height) {
leftRight = 0
context.fillRect(leftRight,upDown1,1,1);
upDown1 +=1
}
else
{
if(leftRight < this.canvas.width -2) {
leftRight+= 1;
context.fillRect(leftRight,upDown1-1,1,1);
}
}
}
}
}
}while(cindex < arg.length)
}
function componentToHex(c) {
var hex = Number(c).toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
ColorizeData.prototype.colorToText = function(arg)
{
var text = "";
var context = this.canvas.getContext("2d";
var size = 0;
for(var index = 0;index<4;index++)
{
switch (index)
{
case 0:
imgData = context.getImageData(0,0, this.canvas.width,1);
size = this.canvas.width;
break;
case 1:
imgData = context.getImageData(this.canvas.width - 1,1, 1,this.canvas.height - 1);
size = this.canvas.height - 1;
break;
case 2:
imgData = context.getImageData(0,1, 1,this.canvas.height - 1);
size = this.canvas.height - 1;
break;
default:
imgData = context.getImageData(1,this.canvas.height -1, this.canvas.width-2, 1);
size = this.canvas.width - 2;
}
for(var i = 0; i < size; i += 4) {
//hide this pixel.
imgData.data[i + 3] = 0;
//check red for 0
if(imgData.data[i + 0] != 0)
{
text += this.decToCharTable[imgData.data[i + 0]];
}
else
{
break;
}
//check green for 0
if(imgData.data[i + 1] != 0)
{
text += this.decToCharTable[imgData.data[i + 1]];
}
else
{
break;
}
//check blue for 0
if(imgData.data[i + 2] != 0)
{
text += this.decToCharTable[imgData.data[i + 2]];
}
else
{
break;
}

}
switch(index)
{
case 0:
context.putImageData(imgData,0,0);
break;
case 1:
context.putImageData(imgData,this.canvas.width - 1,1);
break;
case 2:
context.putImageData(imgData,0,1);
break;
case 3:
context.putImageData(imgData,1,this.canvas.height -1);
break;
default:
alert("fail";
}
}
document.getElementById(arg).innerText = text;
}
ColorizeData.prototype.loadImage = function(arg) {
var canvas = document.getElementById("myCanvas";
var context = canvas.getContext("2d";
var img = new Image();
img.onload = function () {
context.drawImage(img, 0, 0, 200, 200);
};
img.src = arg;
}
ColorizeData.prototype.loadImageAndRead = function(arg) {
var canvas = document.getElementById("myCanvas";
var context = canvas.getContext("2d";
var img = new Image();
img.onload = function () {
context.drawImage(img, 0, 0, 200, 200);
Colorizer.colorToText('Start');
};
img.src = arg;
}
ColorizeData.prototype.loadImageAndWrite = function(arg) {
var canvas = document.getElementById("myCanvas";
var context = canvas.getContext("2d";
var img = new Image();
img.onload = function () {
context.drawImage(img, 0, 0, 200, 200);
Colorizer.textToColor(document.getElementById("WriteThis".value);
};
img.src = arg;
}

ColorizeData.prototype.clear = function() {
var context = this.canvas.getContext("2d";
context.clearRect(0,0,this.canvas.width, this.canvas.height);
}
var Colorizer = new ColorizeData(document.getElementById("myCanvas");
Colorizer.initTables();
Colorizer.textToColor("Testing 123...";

</script>
</body>
</html>


Example of (1st) generation image is attached. This code is 3rd generation, translation tables changed so it wont work for this image.
1st generation code is here.
http://codereview.stackexchange.com/questions/77746/converting-text-to-colored-pixels-and-back-again

Thanks for all the decent reading material.

BanMe_2
February 1st, 2015, 20:01
I want to learn, even while I am dying.

http://stackoverflow.com/questions/28441774/i-need-help-implementing-this-algorithm-for-the-1worldsync-dam-api ("http://stackoverflow.com/questions/28441774/i-need-help-implementing-this-algorithm-for-the-1worldsync-dam-api")

BanMe_2
December 26th, 2015, 10:48
I have more than the arts in mind kayaker.

I plan to use this concept to reduce http traffic on the web, by embedding content into images and have the client parse the images with javascript.

(Re)think my idea's please.

blabberer
December 26th, 2015, 14:21
Quote:

BanMe_2

I want to learn, even while I am dying.

http://stackoverflow.com/questions/28441774/i-need-help-implementing-this-algorithm-for-the-1worldsync-dam-api



are you still stuck on the damapi ??
iirc you opened another thread here on the same damapi
if you are struck use this powershell script

i don't know if it works with your data or not in the link but it works with the damapi pdf example correctly

Code:

$a = New-Object System.Security.Cryptography.HMACSHA256
$a.key = [Text.Encoding]::ASCII.GetBytes($args[1])
[Convert]::ToBase64String($a.ComputeHash([Text.Encoding]::ASCII.GetBytes($args[0])))


run as

Code:


:\>powershell -f hmack.ps1 "/V2/assets?app_id=12345& ipGLN=1234567891234&senderGLN=1234567891234&TIMESTAMP=2012-12-06T13:08:02Z" 6
b904a0c5ceefa991b2ebc9cfec202b6
xCimvrWfNZ3o83wugChCU0oaaaP9vIfztHi9TMhgoYA=



the input and output can be verified from page 36 of the damapi.pdf (retrieved around the date of the other damapi thread)

BanMe_2
December 27th, 2015, 02:05
That's a pretty small implementation. But I finished it all. got it all working synchronously and then there like ok use it to upload 20k images.. it was to slow so I looked into speed it up with asynchronous tasks and was unable to get it to work properly so I reverted to type and wrote a html page with a javascript multi drop file handler for image files, made the load code wrap in a xml file with some predefined variables, zipped them up and sent them on as2 connection. :] But thank you for the effort good citizen. I appreciate it.

On a side note I have been thinking about something, that you might be able to help me with, has to do with javascript.

But I was wondering, if an idea I had was feasible, from my laymen perspective could 2 RGBA webgl pixels be combined to form a register?Could we define 0 as black or white and perform shader operations on the set color values? I mean couldn't we colorize a pair of RGBA 4 bytes each into a qword length buffer and store data in registers, and compare how far away from black or white it is to determine the value of it. The pixel paired registers could then be used to process instructions from some source.
I should patent the ideas I have, but I choose to just give them to the winds...

blabberer
December 27th, 2015, 11:30
well to be frank i have no idea my JavaScript know-how is very limited
just because i wanted to get into my head something before i can make a half or quarter sensisible reply i followed into the
link (first generation thingy) a brief glance tell me you want to make some thing like this


Code:

Add-Type -AssemblyName *sys*forms*
Add-Type -AssemblyName System.Drawing
$fg=($f=New-Object Windows.Forms.Form).createGraphics()
$f.Width=350;$f.Height=70;$f.Text="Banme Games"
$table=@{
"a"="#000020";"b"="#000040";"c"="#000060";"d"="#000080";"e"="#0000a0";"f"="#0000c0";
"g"="#0000e0";"h"="#001010";"i"="#002030";"j"="#003050";"k"="#004070";"l"="#005090";
"m"="#0060b0";"n"="#0070d0";"o"="#0080f0";"p"="#009020";"q"="#00a040";"r"="#00b060";
"s"="#00c080";"t"="#00d0a0";"u"="#00e0c0";"v"="#00f0e0";"w"="#102010";"x"="#204030";
"y"="#306050";"z"="#408070";" "="#50a090";"-"="#60c0b0";"="="#70e0d0";"0"="#800000";
"1"="#801000";"2"="#802000";"3"="#803000";"4"="#804000";"5"="#805000";"6"="#806000";
"7"="#807000";"8"="#808000";"9"="#809000";"@"="#000000";"!"="#000000";
};
$in = "hello ban me @ 42 d0wnning greet!";3024
$i = $j = $k = 0;
$p = @(0..50);
$in.ToCharArray() | %{
$p[$j++] = New-Object Drawing.Solidbrush ($table.Item($_.tostring()))
$f.add_paint({$fg.FillRectangle($p[$k++],($i+=10),10,5,10)})
} $f.ShowDialog() > null




BanMe_2
December 27th, 2015, 12:48
Excellent stuff this what looks to be javascript, but probably is powershell.. excellently small. but no, I meant in a canvas with a pixel and a fragment shader.

This link might help in clarifying, what I am talking about.

http://nullprogram.com/blog/2014/06/10/

I also heard about storing data in images even if they are resized? Is there further reading material for this as well? I need to be less of a librarian or something.. sorry.

Also greetz to you blabberer, much respect for the truths.

001010 0000a0 005090 005090 0080f0 50a090 000040 801000 000020 000040 00004 0000a0 00b060 0000a0 00b060.

and yes blabber png is the extension I misspoke before.but it doesn't matter, because you don't need to load and render the image on the canvas, because the canvas is the image. That's some "there is no spoon" shit right there if I ever saw it..

BanMe_2
December 29th, 2015, 11:14
That is what I want to do, and I would like to do that in the gpu's renderings.So Not Image processing,processing in a image, emulated but realtime rendered. executing the input and giving a output instruction by instruction on something in that image and 'could' be rendered in a web page.

scrape a concept™ from UNU project

Maybe the question you ask yourself, is why the fuck does this bloke want to do any of this, what is his end goal, I have no fucking idea, but I do try and explore things and ideas differently because I wish to have my own. Even if it is coupling the many disparate and unrelated fields of my interests together.

BanMe_2
December 30th, 2015, 11:49
Took me a bit to find the tools necessary to understand, and go forth with my own understanding. But I found a i8080 processor emulator that plays space invader.
There are reasons, I chose these, and low that they are limited, in their limitation(s) there is always a maximum to be achieved with careful rethought after the initial implementation.

Like for instance a dynamically resizable register length as long as 'space' is available., like implementing instructions that are complemented by the parallelism involved in graphics processing in the GPU.


http://typedarray.org/intel-8080-cpu-emulation-in-javascript/

So then I thought to myself. Well that's cool but what about a disassembler. found one.

https://github.com/begoon/i8080-js - disasm

I now have some grasp of the concepts and patterns involved. So On to the next part reimplementing the primitives, with webgl.

So what do I mean by the primitives? I mean the cpu embedded screen, IO,Memory, instructions registers flags and so forth, viewed totally.

I plan to ferret this one out..

I do this because, in my view the scene never died. It is in all of us, and in the time machine of the web.


So in the spirit described hence I come here; I am going behave in a respectable manner, and try and re-ignite community thinking, as group activity, and push for discourse.

Kayaker
December 30th, 2015, 17:08
Well like that doesn't sound interesting. A couple of things that you've probably come across before that might help in your thought processes if not in the actual implementation:

ODA Online Disassembler. According to the blog, it's built on libbfd and libopcodes (part of binutils) and recognizes PE, ELF and Mach-O files. I can't tell if your JS version supports all OS formats. Not sure if that fits in with your WebGL ideas but wanted to mention it.

https://www.onlinedisassembler.com/odaweb/
http://blog.onlinedisassembler.com/blog/?p=44

For the emulation, I immediately thought of Ida-x86emu. Again it may not be directly relevant but there is source code which might help with the implementation of your JS version.

http://www.idabook.com/x86emu/

For sure keep us updated on whether this crazy scheme will work

Regards,
Kayaker

BanMe_2
December 30th, 2015, 17:51
I have heard of ODA, and actually suggested it as a tool to disassemble hex, but it is in the raw and has no idea of the system behind it, which could lead to data being interpreted as instructions..

I understand that subsetting to javascript and even further than that to webgl, limits the portability of the implementation, but as blabberer demonstrated and was once a requirement to the strains, reimplementation of ideas is easy if the tools are available to you and you have some want to seek.

My thought is to start small, and work my way up, like this arcade game, then maybe x86.. But I will take a look, and thank you for your interest.

Regards,
BanMe_2

BanMe_2
January 4th, 2016, 17:35
Quote:
[Originally Posted by "Kayaker"]I can't tell if your JS version supports all OS formats.


Ok so reconsidering this specific part, I have come to agree with you on this respect. I think that doing this in C++ would be more beneficial. Especially with the example planes on the internet. The C++ OpenGL pot is much bigger then the recent WebGL developments.

Next up is how to emulate a CPU in OpenGL 3.2. I do not want to make anything that looks like a CPU visually speaking. I want to use opengl functionalities to implement the functionality of the 8080.

So my question(s) to myself are; "What are the some way(s) to attack this problem?", and "What tactics did others use to solve similar problems to this one?" I will try and answer these questions and form some kinda of similar functionality mapping table between the js 8080 version and C++ opengl. I welcome everyone's input, and would gladly include your name and or code into a final design decision.