You questions seem to be predominantly focused on arrays. The array layout is very nicely specified (with lots of comments) here: https://github.com/JuliaLang/julia/blob/01abdc3f2bc0e3611cf14aa331cdc6a10f0dfa0e/src/julia.h#L142-L178
Also, take a look at the help for pointer_to_array: http://docs.julialang.org/en/release-0.3/stdlib/c/#Base.pointer_to_array Those two things, taken together, I think will answer a lot of your questions. In short: when Julia allocates an array itself, it typically tries to keep the data immediately following the header. This helps with the cache-line-locality issues you're looking at. If, however, you need to create an array from a random pointer (or shared with another Julian array — like reshape currently does), it cannot just insert its header inline into memory. So it uses a pointer to a different memory region in those cases. That's why, for example, you can't grow a vector obtained by reshape. For GC, you must tell pointer_to_array if it is to take ownership of the data. If Julia should "own" the pointer, GC will call free on it. You have a lot of disjointed questions in your post, but I hope that this gives you enough information to answer the remainder on your own. Part of the beauty of open source is you can find these answers fairly easily. Matt On Saturday, June 6, 2015 at 5:58:02 AM UTC-4, Páll Haraldsson wrote: > > Hi, > > [General issue on specification [promise] in B.] > > A. > [Are all allocations in Julia cache-line aligned (or at least 32-byte > aligned, that is the common size)? I'm not asking for a specification of > 32-byte aligned or whatever the size of cache-line is, but a big/ger, > appropriate for speed, alignment would be nice.. - and a way to ask for > that size..] > > > I assume Julia's allocations as are at least word aligned as they *should > be* (as any sane allocator, say (good) malloc in C). But in Julia and C > pointers (not allocations, I might be wrong about C in some version..?) can > be byte aligned. > > [Since Julia can manage/take over memory allocated in C, that answers my > question, if allocations there can be byte aligned.. Or maybe Julia doesn't > handle all versions of malloc in C?] > > > Now, in C you can point in the middle of your allocated array and that is > ok as you have to deallocate yourself.. In Julia I have to rely on the GC > and this seems tricky to test (that an object will not turn into garbage > with only a byte pointer to it) or look for in the (low-level I guess..) > Julia code. Anyway, that code could change.. > > > [I know an index/cursor, with-in the array, is a possibility. I however, > want a pointer in my object to point with-in my own (sub-)object and have > the possibility of reallocating on the heap and move and point outside of > my own object. Hope you follow..] > > > What I'm saying, really, is there an (implicit, that should maybe be > explicit?) specification for how at least the GC should handle things? > Note, I'm not only talking about pointing to the start of a sub-object of > an (compound) object, but as described with-in, say, a Uint8 array. > > [Would it matter if the types differ? Say you have a Uint16 array, could > you have a pointer to Uint8 of either byte therein?] > > > B. > In general, I'm not sure having a full specification of Julia is too > useful and not asking for that.. With Julia's permissive MIT licensed code > (and macros.. that allow many (most all?) extensions..) I'm hoping there > will be no major forks of Julia.. I'm pretty sure there will not be any > reimplementation of full Julia from scratch (why would anyone?). > > > I can only really forsee a full reimplementation of the GC (already done.. > right?, and maybe again, say for (thread-safe and/or) full-hard-realtime.. > might need to be a separate julia binary or switchable GC..). > > > Do we need a specification promise like: > > https://golang.org/doc/go1compat > > > C. > I know you can look up the cache-line size of the CPU (on Linux) in /proc. > Do you know of a cross-platform way (or just for the other platforms so I > could make code in Julia)? If you need some specific instructions like, > CPUID, then I guess you are out of luck with Julia.. Or you really want > this to be part of the OS API anyway. > > [Only knowing the cache-size alignment is helpful, but less so if the > allocations are not aligned..] I'm counting, not cycles so much, but > cache-misses. > > > D. > To access an object (on the heap) I can expect one cache-miss. And another > getting the size of the object? I'm not sure where that is stored, "with-in > the object allocation" (just preceding?)? Or in metadata separate from it? > Anyway, it might be a separate cache-line, but accesses to adjacent > cache-lines should be faster than distant ones? > > -- > Palli. > >
