relax | RelaX - a relational algebra calculator | Math library
kandi X-RAY | relax Summary
kandi X-RAY | relax Summary
A relational algebra calculator.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of relax
relax Key Features
relax Examples and Code Snippets
def get_input_params(distribution_strategy,
num_samples,
steps,
batch_size,
mode=None):
"""Calculate the number of batches and steps/steps_per_epoch.
Args:
d
def build_recursive_hd_all_reduce(input_tensors, red_op, un_op=None):
"""Construct a subgraph for recursive halving-doubling all-reduce.
The recursive halving-doubling algorithm is described in
(Thakur et al., 2015).
The concept is to arran
def summary_scope(name, default_name="summary", values=None):
"""Experimental context manager for use when defining a custom summary op.
This behaves similarly to `tf.name_scope`, except that it returns a generated
summary tag in addition to t
Community Discussions
Trending Discussions on relax
QUESTION
This is a question about traversing mutually recursive data types. I am modeling ASTs for a bunch of mutually recursive datatypes using Indexed Functor as described in this gist here. This works well enough for my intended purposes.
Now I need to transform my data structure with data flowing top-down. here is an SoF question asked in the context of Functor where it's shown that the carrier of the algebra can be a function that allows one to push data down during traversal. However, I am struggling to use this technique with Indexed Functor. I think my data type needs to be altered but I am not sure how.
Here is some code that illustrates my problem. Please note, that I am not including mutually recursive types or multiple indexes as I don't need them to illustrate the issue.
setDepth should change every (IntF n) to (IntF depth). The function as written won't type check because kind ‘AstIdx -> *’ doesn't match ‘Int -> Expr ix’. Maybe I am missing something but I don't see a way to get around this without relaxing the kind of f to be less restrictive in IxFunctor but that seems wrong.
Any thoughts, suggestions or pointers welcome!
...ANSWER
Answered 2022-Apr-01 at 22:53I'm assuming here that you're trying to set each IntF
node to its depth within the tree (like the byDepthF
function from the linked question) rather than to some fixed integer argument named depth
.
If so, I think you're probably looking for something like the following:
QUESTION
I've been reading this post of Jeff Preshing about The Synchronizes-With Relation, and also the "Release-Acquire Ordering" section in the std::memory_order page from cpp reference, and I don't really understand:
It seems that there is some kind of promise by the standard that I don't understand why it's necessary. Let's take the example from the CPP reference:
...ANSWER
Answered 2022-Mar-29 at 15:00This ptr.store(p, std::memory_order_release)
(L1) guarantees that anything done prior to this line in this particular thread (T1) will be visible to other threads as long as those other threads are reading ptr
in a correct fashion (in this case, using std::memory_order_acquire
). This guarantee works only with this pair, alone this line guarantees nothing.
Now you have ptr.load(std::memory_order_acquire)
(L2) on the other thread (T2) which, working with its pair from another thread, guarantees that as long as it read the value written in T1 you can see other values written prior to that line (in your case it is data
). So because L1 synchronizes with L2, data = 42;
happens before assert(data == 42)
.
Also there is a guarantee that ptr
is written and read atomically, because, well, it is atomic. No other guarantees or promises are in that code.
QUESTION
I'm having some trouble with some code I wrote that appears to work on the desktop, but when copied to my raspberry pi/touchscreen, I get a purely blank screen. Rpi has kivy installed. Kivy demos work just fine on both systems. Is there a chance there is something with import Window on kivy? Any advice would be greatly appreciated!
EDIT 1: I read online of someone else with a similar issue, needed to add (from kivy.lang.builder import Builder) and (Builder.load_file.py). I added this in the python code, which is letting me see most of the original program. Some of Kivy is showing, though for some reason- the graphic menu.png is missing and so is the textbox/grid layout at the bottom of the page (bottom of the kivy code below). This may be due to my positioning, so I will look into this.
Edit 2: This should be resolved- it was implementing Builder to the python code (correct version seen below). I also discovered- the raspberry pi might have an issue with images named 'menu.png'... Just changed the name of the image and everything was visible. No idea on that one. Thanks for the assistance.
Python Code:
...ANSWER
Answered 2022-Mar-23 at 03:26Had the same issue. Solved it by increasing the memory dedicated to the GPU on the Raspberry Pi.
Edit your /boot/config.txt
file (sudo
required)
Scroll down to the [all]
section, and edit the gpu_mem
line as follows:
gpu_mem=256
Then reboot your pi.
QUESTION
I have a question about the definition of the synchronises-with relation in the C++ memory model when relaxed and acquire/release accesses are mixed on one and the same atomic variable. Consider the following example consisting of a global initialiser and three threads:
...ANSWER
Answered 2022-Mar-17 at 14:01Because you use relaxed ordering on a separate load & store in T2, the release sequence is broken and the second assert can trigger (although not on a TSO platform such as X86).
You can fix this by either using acq/rel ordering in thread T2 (as you suggested) or by modifying T2 to use an atomic read-modify-write operation (RMW), like this:
QUESTION
I am working with post-processing of the log file arranged in the following format:
...ANSWER
Answered 2022-Mar-08 at 12:41You may use this sed
:
QUESTION
in a lock-free queue.pop(), I read a trivialy_copyable variable (of integral type) after synchronization with an atomic aquire inside a loop. Minimized pseudo code:
...ANSWER
Answered 2022-Feb-20 at 23:05Yes, it's UB in ISO C++; value = data[oldReadPosition]
in the C++ abstract machine involves reading the value of that object. (Usually that means lvalue to rvalue conversion, IIRC.)
But it's mostly harmless, probably only going to be a problem on machines with hardware race detection (not normal mainstream CPUs, but possibly on C implementations like clang with threadsanitizer).
Another use-case for non-atomic read and then checking for possible tearing is the SeqLock, where readers can prove no tearing by reading the same value from an atomic counter before and after the non-atomic read. It's UB in C++, even with volatile
for the non-atomic data, although that may be helpful in making sure the compiler-generated asm is safe. (With memory barriers and current handling of atomics by existing compilers, even non-volatile makes working asm). See Optimal way to pass a few variables between 2 threads pinning different CPUs
atomic_thread_fence
is still necessary for a SeqLock to be safe, and some of the necessary ordering of atomic loads wrt. non-atomic may be an implementation detail if it can't sync with something and create a happens-before.
People do use Seq Locks in real life, depending on the fact that real-life compilers de-facto define a bit more behaviour than ISO C++. Or another way to put it is that happen to work for now; if you're careful about what code you put around the non-atomic read it's unlikely for a compiler to be able to do anything problematic.
But you're definitely venturing out past the safe area of guaranteed behaviour, and probably need to understand how C++ compiles to asm, and how asm works on the target platforms you care about; see also Who's afraid of a big bad optimizing compiler? on LWN; it's aimed at Linux kernel code, which is the main user of hand-rolled atomics and stuff like that.
QUESTION
I have a shared data structure that is already internally synchronised with a mutex. Can I use an atomic with memory order relaxed to signal changes. A very simplified view of what I mean in code
Thread 1
...ANSWER
Answered 2022-Feb-10 at 16:08Relaxed order means that ordering of atomics and external operations only happens with regard to operations on the specific atomic object (and even then, the compiler is free to re-order them outside of the program-defined order). Thus, a relaxed store has no relationship to any state in external objects. So a relaxed load will not synchronize with your other mutexes.
The whole point of acquire/release semantics is to allow an atomic to control visibility of other memory. If you want an atomic load to mean that something is available, it must be an acquire and the value it acquired must have been released.
QUESTION
What would be the minimally needed memory barriers in the following scenario?
Several threads update the elements of an array int a[n]
in parallel.
All elements are initially set to zero.
Each thread computes a new value for each element; then,
it compares the computed new value to the existing value stored in the array,
and writes the new value only if it is greater than the stored value.
For example, if a thread computes for a[0]
a new value 5
, but
a[0]
is already 10
, then the thread should not update a[0]
.
But if the thread computes a new value 10
, and a[0]
is 5
,
then the thread must update a[0]
.
The computation of the new values involves some shared read-only data; it does not involve the array at all.
While the above-mentioned threads are running, no other thread accesses the array. The array is consumed later, after all the threads are guaranteed to finish their updates.
The implementation uses a compare-and-swap loop, wrapping the elements
into atomic_ref
(either from Boost or from C++20):
ANSWER
Answered 2022-Feb-08 at 20:54Relaxed is fine, you don't need any ordering wrt. access to any other elements during the process of updating. And for accesses to the same location, ISO C++ guarantees that a "modification order" exists for each location separately, and that even relaxed
operations will only see the same or later values in the modification order of the location between loaded or RMWed.
You're just building an atomic fetch_max
primitive out of a CAS retry loop. Since the other writers are doing the same thing, the value of each location is monotonically increasing. So it's totally safe to bail out any time you see a value greater than the new_value
.
For the main thread to collect the results at the end, you do need release/acquire synchronization like thread.join
or some kind of flag. (e.g. maybe fetch_sub(1, release)
of a counter of how many threads still have work left to do, or an array of done
flags so you can just do a pure store.)
BTW, this seems likely to be slow, with lots of time spent waiting for cache lines to bounce between cores. (Lots of false-sharing.) Ideally you you can efficiently change this to have each thread work on different parts of the array (e.g. computing multiple candidates for the same index so it doesn't need any atomic stuff).
I cannot guarantee that the computed indices do not overlap. In practice, the overlapping is usually small, but it cannot be eliminated.
So apparently that's a no. And if the indices touched by different threads are in different cache lines (chunk of 16 int32_t
) then there won't be too much false sharing. (Also, if computation is expensive so you aren't producing values very fast, that's good so atomic updates aren't what your code is spending most of its time on.)
But if there is significant contention and the array isn't huge, you could give each thread its own output array, and collect the results at the end. e.g. have one thread do a[i] = max(a[i], b[i], c[i], d[i])
for 4 to 8 arrays per loop. (Not too many read streams at once, and not a variable number of inputs because that probably couldn't compile efficiently). This should benefit from SIMD, e.g. SSE4.1 pmaxsd
doing 4 parallel max
operations, so this should be limited mostly by L3 cache bandwidth.
Or divide the max work between threads as a second parallel phase, with each thread doing the above over part of the output array. Or have the thread_id % 4 == 0
reduce results from itself and the next 3 threads, so you have a tree of reductions if you have a system with many threads.
QUESTION
I basically have the following code snippet:
...ANSWER
Answered 2021-Sep-20 at 14:16To answer the question in your title, there is no real relationship between atomics and sequence points.
The code as written does guarantee that the compiler must execute the atomic_fetch_sub
before the atomic_load
. But these functions are (in C's memory model) simply requests to the platform to perform certain actions on certain pieces of memory. Their effects, when they become visible to who, are specified by the memory model, and the ordering parameters. Thus even in the case when you know request A comes before request B, that does not mean the effects of request A are resolved before request B, unless you explicitly specify it to be.
QUESTION
Warning messages like:
missing 'typename' prior to dependent type name ... [-Wtypename-missing]
and
template argument for template type parameter must be a type; omitted 'typename' is a Microsoft extension [-Wmicrosoft-template]
If I understand right c++20 relaxed the need for typename
. Does this mean that these warnings are outdated? Or should I add the (annoying) typename
whenever there is warning? (I'm using Visual Studio / Clang12 / std=C++20.)
ANSWER
Answered 2022-Jan-22 at 12:23No, the warning is useful. Fix your code.
C++20 relaxed the typename
rules a little bit. But it's unrelated to this warning.
MSVC considers typename
to be (almost?) completely optional, and is non-conforming in this regard. Clang apparently can do that too, for compatibility with MSVC. The warning says that your code is non-conforming, and might not work on other compilers (most notably on GCC).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install relax
Install node https://nodejs.org/en/
Clone the repo
Checkout the development branch
Execute yarn install to install all dependencies
Execute yarn serve to locally run the webapp on port 8088
(Optional) open folder with https://code.visualstudio.com/ and install the workspace recommended extensions (includes tasks)
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page