Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taco generates invalid "#pragma omp atomic" for Store ops #316

Closed
Infinoid opened this issue Sep 28, 2020 · 4 comments
Closed

taco generates invalid "#pragma omp atomic" for Store ops #316

Infinoid opened this issue Sep 28, 2020 · 4 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@Infinoid
Copy link
Contributor

In the scheduling_eval.test_spmvCPU_temp test, Taco generates the following code:

    #pragma omp atomic
    y_vals[i] = tjy_val;

On Debian bullseye (testing), this fails to compile with the following error:

[ RUN      ] scheduling_eval.test_spmvCPU_temp
/tmp/taco_tmp_4Ids2M/1wry7ti8f7ci.c: In function ‘compute’:
/tmp/taco_tmp_4Ids2M/1wry7ti8f7ci.c:137:24: error: invalid form of ‘#pragma omp atomic’ before ‘;’ token
  137 |     y_vals[i] = tjy_val;
      |                        ^
Error at /home/infinoid/workspace/taco/taco/src/codegen/module.cpp:154 in compile:
 Compilation command failed:
gcc-10 -O3 -ffast-math -std=c99 -shared -fPIC -fopenmp /tmp/taco_tmp_4Ids2M/1wry7ti8f7ci.c  -o /tmp/taco_tmp_4Ids2M/1wry7ti8f7ci.so -lm
returned 256
[  FAILED  ] scheduling_eval.test_spmvCPU_temp (190 ms)

The test passes on ubuntu-20.04 and ubuntu-18.04. I think they added some new checks in the new compiler version. (gcc and libgomp1 version 10.2.0)

git bisect indicates that the test starts failing in e976ecb. Prior to that commit, the code generated was:

    #pragma omp atomic
    y_vals[i] = y_vals[i] + tj_val;

This compiles successfully; the new syntax does not.

This Store op doesn't appear to need atomics. Each thread has different values of i, and this is the only place y_vals[i] is accessed, so the accesses should be safe. But if it does need it, adding a "write" at the end (#pragma omp atomic write) is enough to make the compiler happy again.

For convenience, I posted generated source files for current and "last known working" versions at https://gist.github.com/Infinoid/1692a5963997fa5bccbaf42b0b29cc67 .

@stephenchouca stephenchouca self-assigned this Sep 28, 2020
@stephenchouca stephenchouca added the bug Indicates an unexpected problem or unintended behavior label Sep 28, 2020
@Infinoid
Copy link
Contributor Author

Infinoid commented Dec 7, 2020

I also see this failure on ubuntu 16.04 with gcc/libgomp1 version 5.4.0.

@Infinoid
Copy link
Contributor Author

Infinoid commented Dec 9, 2020

adding a "write" at the end (#pragma omp atomic write) is enough to make the compiler happy again.

This is definitely not the right fix... it causes other tests to fail.

@stephenchouca
Copy link
Contributor

This should be fixed in the latest commit on master. Let me know if there's some issue with the fix.

Infinoid added a commit to Infinoid/taco that referenced this issue Feb 12, 2021
Infinoid added a commit to Infinoid/taco that referenced this issue Feb 12, 2021
@Infinoid
Copy link
Contributor Author

Yep, 0a48d17 fixed this. #402 adds a test case to ensure that atomics are retained in cases where they are still needed.

stephenchouca added a commit that referenced this issue Feb 12, 2021
Add a SpTV+openmp+atomics test case for #316
guilhermeleobas pushed a commit to Quansight-Labs/taco that referenced this issue May 27, 2021
* Reimplemented parts of attribute query lowering and some optimizations

* Add a test case for mixing sparse/dense formats in matrix multiply

The test case does A=BC, and tries all permutations of Dense, CSR, CSC, and COO.
It is disabled for now, enable it once sparse output works.

* Add in hoisted workspace reuse and remove guard for divisible bound and split

* Fix some workspaces tests

* Use CUDA_LIBRARIES instead of hardcoding the path to libcudart

Hardcoded paths don't work when using Debian's packaged version of cuda,
as the library paths don't match.  CMake's find_package(CUDA) sets
CUDA_LIBRARIES to the path of libcudart, so just use that instead.

* Add TACO_NVCC var to complement TACO_NVCCFLAGS

This is useful for passing specific arguments to nvcc.  In my case,
I wanted to force nvcc to use a specific version of g++.

* Updated automated test workflow

* Updated automated test workflow

* fix -s arg parser

* Prototypes automatically generating code to to have sparse iteration over a dense workspace

* don't run autoscheduling commands if manual schedule is provided in command line tool fixes tensor-compiler#336

* fix fuse bound calculation, which was unnecessarily enlarged. Fixes tensor-compiler#337

* Fixes bugs in check for accelerating workspace

* Fixes bug in concreteNotation check. All workspace tests pass.

* Removes print statements

* fix handling of operator precedence in CUDA backend. Fixes tensor-compiler#338

* Only hoists out malloc + free from where statement when possible. Emits loop to zero every element in a temporary when it is hoisted before the producer is called. Changes the codegens to keep pointer names constant

* Fix build failures on ubuntu 16.04

* Fix python bindings when building with clang++-10

Fix a few instances of this build error in pytaco:
.../python_bindings/src/pyTensor.cpp:406:53: error: unknown type name 'nullptr_t'; did you mean 'std::nullptr_t'?

* Use exceptions for error reporting in all cases

Previously, exceptions were used only when the Python bindings were
enabled.  This meant that C++ applications could only handle errors
gracefully when the Python bindings were enabled.

Change it to consistently use exceptions in all cases.

* Adds negation to pytaco tensor interface

* Removes initialization loop from before producer when accelerating a dense workspacE

* Places index list size above the producer loop when accelerating a dense workspace. This should make the transition to multithreading easier and fixes a bug in the original code

* Fixes workspace reset

* If underived variables are used to index a workspace, we allocate space for the workspace based on the size of the sizes of the input tensors

* Relaxes requirements for spmm transformation

* Checks if first mode of last tensor has locate for spmm transform

* Changes SPMM tranform requirement. Unsure about this

* Fix whitespace in tools/taco.cpp.  (No functional changes)

* Report an error properly in the taco CLI tool.

* Use the existing Lexer to parse scheduling directives

Add a schedule parser function.
Add test cases for the schedule parser function.
Use the function in the taco command-line tool.
Return usage messages when the user passes in the wrong number of parameters.

* Silence a warning about cmake policy CMP0054.

* lower,index_notation: fix compilation warnings

Fix a few compilation warnings caused by taking copies of loop variables
instead of references.

* index_notation,error: deduplicate dimension checking routines

Currently, there are two dimension checking methods in TACO. The first
returned a boolean, and the second returned a user readable string
detailing the error. Both methods had nearly identical code. Therefore,
this commit merges them into a single function that returns a boolean
and the error, if it exists.

* lower: fix a bug causing undefined variables when applying fuse

Fixes tensor-compiler#355.

This commit fixes a bug where the fuse transformation would not generate
necessary locator variables when applied to iteration over two dense
variables.

* Revert "lower: fix a bug causing undefined variables when applying fuse"

* Add -help and -help=schedule parameters to CLI

* lower: fix a bug causing undefined variables when applying fuse

Fixes tensor-compiler#355.

This commit fixes a bug where the fuse transformation would not generate
necessary locator variables when applied to iteration over two dense
variables.

Additionally, this commit adds a test for when a dense iteration results
in a transposition of a tensor.

* Emit unsequenced insertion code

* Zeroelss updates

* Emit code to use attribute query results during assembly

* include,src: introduce a true break statement, rename current to continue

The current `ir::Break` statement actually translates to a `continue`.
This commit renames this to `ir::Continue`, and adds a new `ir::Break`
node that actually translates to a `break`. This new node will be used
by upcoming windowing work.

* Don't emit append code if using ungrouped insertion

* Clear the needsCompile flag in tensor->compileSource()

Fixes tensor-compiler#366.

* Add an error message for invalid input tensor names.

* Fix warnings in python bindings

* tensor,codegen: fix a bug where kernel cache could be modified

This commit fixes a bug where upon recompilation of an index statement,
entries in the kernel cache could be inadvertently modified, leading to
confusing segfaults.

An example of the bug is included in the added test, where the second
call to `c(i, j) = a(i, j)` would hit the cache, but then find a module
that had code that corresponded to `c(i, j) = a(i, j) + b(i, j)`.

* Implemented assemble scheduling command + don't sort sparse accelerator if performing reduction

* Assume inputs are zeroless when computing attribute queries

* Replace workspaces in attribute queries

* Enable parallelization of forall statements with results assembled by ungrouped insertion

* Fixed various bugs

* Fixed various bugs

* Deleted redundant code

* Fix workspaces test on ubuntu 16.04

Fixes: tensor-compiler#380

* Add code coverage targets to cmake

* Fix warnings in Release builds

* Fixed attribute query compute code not being emitted + optimize computation of Boolean temporaries when always assigned true

* Emit init_edges code

* Added parallel SpGEMM test

* Fixed heuristic for inserting accelerators for workspaces indexed by derived index variables

* Removed debug print statements

* Updated CMake requirements

* Added correctness checks for ungrouped insertion

* Fix a bug in CLI parsing of bound()

This bug was introduced in tensor-compiler#352.

* Strengthened precondition for assemble command

* Remove pybind11

* Make pybind11 a submodule

* Modify cmake

* fix cmake

* Removes forcecast in function overload

* Add comment to python code explaining when conversion happen

* Don't emit atomic pragma for non-reduction assignments

* *: add support for windowing of tensors

This commit adds support for windowing of tensors in the existing index
notation DSL. For example:

```
A(i, j) = B(i(1, 4), j) * C(i, j(5, 10))
```

causes `B` to be windowed along its first mode, and `C` to be windowed
along its second mode. In this commit any mix of windowed and
non-windowed modes are supported, along with windowing the same tensor
in different ways in the same expression. The windowing expressions
correspond to the `:` operator to slice dimensions in `numpy`.

Currently, only windowing by integers is supported.

Windowing is achieved by tying windowing information to particular
`Iterator` objects, as these are created for each `Tensor`-`IndexVar`
pair. When iterating over an `Iterator` that may be windowed, extra
steps are taken to either generate an index into the windowed space, or
to recover an index from a point in the windowed space.

* Update Cmake to pull python binding during any build

* Add a SpTV+openmp+atomics test case for tensor-compiler#316

* Improve CI test coverage

Add a build step that covers the OpenMP and Python features.

Make it run `make test` to run all available test suites.

* Raise internal error if trying to generate code to assemble sparse accelerator in parallel

* *: add the ability to stride window access

This commit extends the windowing syntax to include an optional third
parameter to a window expression on an index variable:

```
a(i) = b(i(0, n, 5 /* stride */))
```

This stride parameters means that the window should be accessed along
the provided stride, which defaults to 1.

Striding is implemented with a similar idea as windowing, where
coordinates in the stride are mapped to a canonical index space of `[0,n)`.
For compressed modes, coordinates that don't match the stride are
skipped.

* Fixed various bugs

* Fixed removal of redundant loops

* lower: fix a bug when using OpenMP and windowing

Fixes tensor-compiler#409.

This commit fixes a bug where position loops parallelized with OpenMP
that operated over windowed tensor modes would fail to compile.

This commit also fixes some compilation errors compiling windowing tests
on Ubuntu.

* Unbreak cmake build of python bindings

* Remove redundant allocation

* *: add support for using arbitrary indexing sets to window tensors

This commit adds support for using vectors to index arbitrary dimensions
of tensors. It works by packing the vector into a sparse tensor, and
coiterating over the sparse tensor to efficiently filter the chosen
dimensions. The syntax of indexing sets look as follows:

```
A(i) = B(i({1, 3, 5}))
```

which means that only elements 1, 3, and 5 from `B` will be used in the
computation.

* index_notation: implement the `divide` transformation

The divide transformation divides a loop up into `n` equal components,
whereas split breaks a loop up into a components of size `n`.

It also enables support for the transformation in the TACO CLI.

* Enable CI tests for array_algebra branch

* Suppress GCC warnings

* Fixed heuristic for inserting sparse accelerator

* Revert "Fixed heuristic for inserting sparse accelerator"

This reverts commit 4e264ce.

* Fixed heuristic for inserting sparse accelerator

* Fix package version issue in CI tests

Run "apt-get update" to update the package list.

* cuda: fix windowing test with cuda

Fixes tensor-compiler#422.

This commit ensures that the allocation clearing logic is applied to
the CUDA backend as well. The windowing test caught this because TACO
was automatically parallelizing the loop onto the GPU.

* index_notation,tensor: small bugfixes for index sets

* Fixes a runtime error when using index sets on tensors not of integer types
* Fixes a compile error when using a vector typed variable as argument
  for an index set.

* Allow CLI precompute() to specify the workspace name

* Add tracking/reporting of build info

* CLI tool treats double hyphens as a single hyphen

* lowerer_impl: fix some striding bugs

Fixes some formulaic errors in generated striding code along with a test
that revealed them.

* Better error message for guarding unguardable loops

* Use full precision when IR printing float constants

The default precision when printing a floating point value is 6 digits.
This causes a lot of double values to get truncated. Print these with
full precision to avoid losing data.

* Don't emit redundant code to append edges when inserting into result

* index_notation: fix a bug where windows would be dropped through `+=`

Fixes tensor-compiler#451.

This commit fixes a bug where windows applied to index variables would
be dropped when assigned to via the `+=` operator.

* Fixed printing of scheduling commands in command-line tool output

* Fixed precompute transformation and attempt at fixing tensor-compiler#389. Also generate more optimized attribute query code for parallel sparse tensor addition

* Modified MTTKRP test to use schedule with precompute

* assemble command now no longer uses fresh index variables in inserted attribute query computations by default

* Fixed typo in command-line tool usage

* Fixed assemble command with dense arrays + improved heuristics for determining whether result needs to be explicitly zero-initialized

* Fixed how parallelize command checks for races

* Fixing merge issues

Co-authored-by: Stephen Chou <[email protected]>
Co-authored-by: Mark Glines <[email protected]>
Co-authored-by: Olivia Hsu <[email protected]>
Co-authored-by: Stephen Chou <[email protected]>
Co-authored-by: roastduck <[email protected]>
Co-authored-by: Rawn <[email protected]>
Co-authored-by: Ryan Senanayake <[email protected]>
Co-authored-by: Rohan Yadav <[email protected]>
Co-authored-by: Changwan Hong <[email protected]>
Co-authored-by: Rohan Yadav <[email protected]>
Co-authored-by: Sam Kaplan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants