Beta Gen Documentation
hello everyone. This information will be included with the next release, but until then here is some beta documentation describing the new Gen technology. Any feedback is appreciated, particularly if there are subjects that could use more detail or are missing, confusing terminology or descriptions, ...
Here's the link:
https://cycling74.com/download/gen.documentation.beta.pdf
Hi Wesley,
Jumping the gun a bit, but will there be an SDK for [gen~] operators at any point? That would really be the icing on the cake.
An SDK is something we are hoping for a future release (no promises although I really want to see it too). I will say it won't be in a 6.0 release though.
Excellent document - like many others I am very enthusiastic about gen and its Jitter cousins. A few questions:
- GenExpr language: in the case of only being interested in one return value from an expression, the document describes the case where you assign the first return value to a variable but discard the second. Is there a way to reverse this - to discard the first return value and assign the second?
- is the namespace in codebox global - i.e. if I define a function in one codebox can it be called in another?
- is it possible to add the equivalent of the history operator in a jit.gen or (more importantly) jit.gl.gen context? This would be an extremely elegant way to allow for feedback processes, but I don't know if it's feasible. As FBO's are not readable in GLSL I'd imagine the answer is no, but worth asking.
"- GenExpr language: in the case of only being interested in one return value from an expression, the document describes the case where you assign the first return value to a variable but discard the second. Is there a way to reverse this - to discard the first return value and assign the second?"
// the Gen compiler does dead code elimination, so the variable "notused" won't actually be used
notused, myvar = cartopol(in1, in2);
out1 = myvar;
"- is the namespace in codebox global - i.e. if I define a function in one codebox can it be called in another?"
not currently. We will support some kind of import message in the near near future that will load in files of
function definitions
"- is it possible to add the equivalent of the history operator in a jit.gen or (more importantly) jit.gl.gen context? This would be an extremely elegant way to allow for feedback processes, but I don't know if it's feasible. As FBO's are not readable in GLSL I'd imagine the answer is no, but worth asking."
No. None of the Gen objects support this operator. As you can imagine, for the history operator, we'd have to create a temporary buffer the size of the input matrix for this to work. While technically feasible in jit.gen and jit.pix, it's not at all possible in jit.gl.pix. Since the jitter Gen objects don't suffer from the "single sample" delay problem that MSP objects do in feedback situations, I don't think it's much of a burden to require feedback jitter Gen patchers require the user to loop the output back to a second input.
> Here's the link:
> https://cycling74.com/download/gen.documentation.beta.pdf
Most pictures in the first pages of the document are incorrectly displayed in Adobe Reader (8.1.1) (but are OK in MacOS X's Preview app).
Thanks Wesley - all confirming what I had guessed. It's good to hear that you will support function import at some point in the future.
Thanks Roald. I'm seeing the same in Acrobat Pro. Really odd! Looks like the print to PDF function munged some things up.
Really useful document, thanks! I've been muddling along with gen~ for the last few days but this makes things much clearer.
A small question - is it possible to use the history operator within a codebox? It currently throws up an error, so I'm guessing it's not allowed. That's a shame if so. It'd be a great way to easily implement more unwieldy filters.
Hi Bacchus,
In the beta, we didn't get to implementing History in a codebox, but for the release this is already in there. The syntax will like this:
y = x + 1; // fwd use of x
x = history(y * 2);
out = y;
note that x is used before it's assigned to. This will _only_ be allowed for feedback operations and we enforce that strictly. Anything else will throw errors.
Ok, that's great to hear! Looking forward to the release version!
Because you asked for comments...
I think it will be very helpful if the docs would answer the following:
1. What are the intended usages? This would need to be supported by examples showing some contrasting implementations as working and commented patches.
2. What are the performance (or other) gains? This would need to be supported by evidence in the form or working and commented patches showing parallel performance with contrasting setups (gen/not gen). It would also be good to have similar working patches highlighting the areas of applications where the advantages can be greatest. And some text explaining where the advantages are unlikely.
Hope you agree. Thanks.
+1.
despite the fact I understand that gen is supposed to be used for more versed users in programming, which is not my case, I would really appreciate to have the use of gen made more clear for a broader audience. I intend to put my efforts on learning how to use gen and the suggestions from jhdkfj39929 sounds very interesting in helping on it.
hi sandroid. Gen is a lower-level patching environment, but our goal is certainly not to limit it to a certain level of user. It should be accessible to everyone. If you have any other ideas or comments about what is/isn't accessible in terms of how Gen is presented in the documentation, please post them here. thanks!
I just posted in this thread something which might be relevant to jhdkfj39929's questions:
thanks wesley and Joshua. I start grasping the reason for really put myself into gen.
I am looking forward for the examples Joshua mentioned in his post. I think they could help "lastminute programmers" like me, who have never programmed anything before getting in touch with max. Related to this, which directions you could point me as a initial ground to start with? in other words: should I get acquainted with languages like C, C++, Java, or even OpenGL, shaders programming before going into gen or gen some how will be self-explanatory. will I need some background on program paradigms (how to organize the program in variables, functions, etc.)?
In general terms, how can somebody who has learned programming from a graphical oriented environment (and its data flow paradigm) be able to grasp this low level programming? I suspect this question goes far being the scope of this forum. But maybe I am wrong...
Anyways, things are getting really exciting with max6 (I have been patching with Jitter - my main interest- last days,and I am very excited with the new possibilities). Somehow I can recover the same thrilling feeling I had in the first time I saw and played with Max in 2001.
thanx
Hi sandroid,
This is a good question. You shouldn't require any special programming knowledge to get started with Gen. In many instances, you will probably find Gen to be very similar to patching in a standard Max patch. I would recommend looking through the included Gen examples and trying to do a little patching yourself to get a better idea. Like anything, it will take some time to get acquainted with all the features and workflow, but if you are already familiar with Max and Jitter, a lot of that knowledge will translate. My advice would be (like learning Max) to start small and try building some simple things, and scale up as you get more confident.
Can we have loops in codebox pls?
Also, no arrays, why are there no arrays? I want to be able to make arrays of history etc...
@veqtor For arrays, I believe you can use data with peek and poke for now. Loops will be coming eventually.
@sandriod Just wanted to reiterate what Andrew said. There's no need to know C or GLSL to start using gen. If you start using codebox, the expression syntax is very simple and if you study any text programming language like JS, Java, GLSL, etc. many of the ideas should translate.
Some simple synthetic benchmark examples in the other thread:
Thank you. Very helpful. I look forward to more examples. Generally, while MAX documentation and tutorials are very good, I feel one type of storytelling is not very well represented. And this is showing/evidencing via completed projects of some sophistication and of immediate aesthetic value (witness Epic Games trying to impress with the demos like Samaritan – cheesy, yes – but advanced).
(Perhaps I should disclose that I am more interested in Jitter and that the audio side of things might be much more mature - I cannot judge.)
Take for example the available tutorials for drawing or shading in MAX 5 (Tutorials 40 and 41). Or, in fact for most of visual processing. They present some(many) option and demonstrate some working setups but the demonstrations are not intended to be visually convincing. In fact, the functionality they show is basic and the outcomes are ubiquitous to many other systems. So, it is hard for students (or even expert users working outside of their typical specialization) to appreciate what is possible or visualize the path from idea to implementation. Or to appreciate the unique strengths (or even weaknesses – being open about them would make the strength that much more convincing) of MAX as the development environment. With many other complex development/design environments, the task of producing such examples is taken up by 3rd parties. Witness Gnomon tutorials for Maya or cmiVFX tutorials for Hounidi (e.g., the one on Procedural Cities), etc., etc. For MAX, such materials are not that readily available.
I am not sure how one can go about it. Maybe people could suggest some interesting/relevant projects that could be build and exhaustively explained by the Cycling people? Or one could commission some expert users to share/annotate their projects for incorporation into tutorials?
If one could see something immediately impressive and have it explained/available for tweaking, the MAX environment would be that much more appealing. The experience of teaching MAX alongside Processing, for example, shows how the availability of many complete and working examples (e.g., via OpenProcessing) is immediately appealing to the students (and educational to all).
Returning to Gen. Apart from seeing what small-grain gains should be possible, I would love to have access to some examples of more complex projects as discussed above. For example: can one build a fast, large-population, multi-threaded agent system using Gen? Can another version of this system be run on GPU, using Gen? Can the new MAX physics be added to it?
Or what can the others suggest?
@jhdkfj39929 Thanks for your feedback. Great points.
We'll be continuing to work on documentation and examples. Right now we're focusing pretty heavily on just getting the software done, but over the next several months we'll be fleshing out with some of the things you mention.
In the meantime I'd suggest you examine the Projects, Toolbox, Article, and Interview web pages where the type of content you are referring to are more likely to exist than the in application tutorials which are designed to simply communicate functionality. We hope to make it easier for users to share large projects and tutorials (almost all of your mentioned examples above come not from the package developers but the community of users).
Regarding Jitter performance, the use of jit.gl.pix is even faster over CPU jitter objects than any of the gains you'll witness in MSP. We'll have more illustrative examples soon, but it's equally mature to the gen~ audio work. Not many examples however.
Regarding your specific questions:
> can one build a fast, large-population, multi-threaded agent system using Gen?
Yes. Simple example in:
examples/jitter-examples/gen/jit.gen.particles.maxpat
> Can another version of this system be run on GPU, using Gen?
Sort of.
> Can the new MAX physics be added to it?
Not to the gen code itself. The code compiled in Gen cannot interface with outside code. The data can move in and out, and one could build something which ties these different parts together in various ways.
Okay, I've got to spend more time developing the software than explaining these things right now, but once we release, I'll get back to helping explain and answer some of these requests.
-Joshua
Good documentation is a real help, and the Max tradition of help files for everything is really useful.
I think the fastest way for me to really get something is through tutorials, and I hope there will be some gen~ tutorials soon. Tutorials offer a glimpse into someone's process and reasoning and this really help with the challenge of building from scratch.
Thanks again. Yes, a more sustained community effort would be good too. Still, things like Processing are free and this is encouraging a sharing culture where whole projects change hands and books with examples follow multi-project themes (cf. The Nature of Code, now that i mentioned agents). In the other communities I mentioned, people pay for tutorials. With MAX neither mode has quite taken off so it seems reasonable that the developers chip in.
"> Can another version of this system be run on GPU, using Gen?
Sort of."
Not nice to tease people...
Sorry. Not trying to tease. Just limited time for forums at the moment.
The caveat is that you have to treat your data as pixels currently, and then what do you do with the data to render? Right now you would then need to move the values back to the CPU. There are lots of creative ways to use jit.gl.pix for gpgpu programming.
In the future, we could have an OpenCL backend for other kinds of data types than vec4 on gpu, and other possible utilities.
thanks Joshua and Andrew for the feedback. I will start small... :)))
looking forward for more examples on how to handle Gen for Jitter (among some other really cool new objects, like Jit.gl.camera, and the improvements in the jit.gl.model).
thanks a lot for this great upgrade in max.
Hi sandroid,
We'll be able to roll out a lot more example and tutorial content for Gen post-release. I know I personally am looking forward to making some "Gen Recipes" when I can get a chance. For now, here is something I whipped up the other day using jit.gl.pix. More soon, hopefully.
Hi, does anyone how to use the "for" operator in codebox, and in general whether it is possible to use in jit.gen cycles?
And yet, as you can take submatrix of the matrix, and vice versa submatrix written in a matrix, in the case when the matrix is greater than two dimensions in jit.gen?
I understand "sample" operator works only with two-dimensional matrices?
Thank you very much!)
hi Artur,
for is a reserved word for a future release. Currently, there is no iteration statement (for, while, ...) in GenExpr.
As for sample and nearest. These are both N-dimensional operators. You can sample a 3D, 4D, even 32D matrix with it. sample uses linear interpolation so for high dimensional matrices, it will become expensive. For example, a 32D matrix will have 2^32 corners for a sampled location that have to be interpolated.
Excuse me, but when I try to use the 3Dmatrix and "sample" ,max error:
Object - clang, Message - jit method no module to jit,
Object - clang, Message - not jitted,
Object - jit_gen_interface, Message - could not derive constructor from patcher,
Here is an example, that I am doing wrong?
parameters a and b are working, and when the parameter with nothing happening.
Immensely grateful))
I mean a "c" parameter does not work, that is the third coordinate.
Thanks for pointing this out. ND sampling is fixed for the next release. It's not in the Gen document right now, but in jitter gen objects, the binary operators (+, -, /, *, %, etc.) can take vector arguments. For example [+ 1 2 3] will add the input to vec(1, 2, 3). In your patch, I noticed you swizzed out the norm components and add them to your params a, b, and c. You can either pack these params as a vector, say [param offset 0 0 0] or do the following [+ a b c].
Thank you. So really it is more convenient)))