-
Notifications
You must be signed in to change notification settings - Fork 195
Description
The issue
With the following tensor contraction operation (Originated from the CCSD routine used in quantum chemistry):
_a020("aaaa")(p1_va, h3_oa, p3_va, h2_oa) += 0.5 *
_a004("aaaa")(p2_va, p3_va, h3_oa, h1_oa) * t2_aaaa(p1_va, p2_va, h1_oa, h2_oa)
I generate a C kernel using the following TACO command:
./build/bin/taco \
'a020aaaa(p1va, p3va, h3oa, h2oa) += 0.5 * a004(p2va, p3va, h3oa, h1oa) * t2aaaa(p1va, p2va, h1oa, h2oa)' \
-c -f=a020aaaa:uccq -f=a004:uccq -f=t2aaaa:uccq
Then I allocate three COO tensors, each filled with initialization values:
A (of shape [13, 3, 5, 17]) = {0.0, 1.0, 2.0, ..., 3314.0};
B (of shape [ 7, 13, 17, 11]) = {0.0, 1.0, 2.0, ..., 17016.0};
C (of shape [ 7, 3, 5, 11]) = {-1e10, -1e10, -1e10, ..., -1e10};
and call the compute
function generated by TACO:
compute(&C, &A, &B);
However, the computation result looks like this:
output[0, 0, 0, 0] = 0.000000
output[0, 0, 0, 1] = 0.000000
...
output[0, 0, 0, 10] = 0.000000
output[0, 0, 0, 0] = 5.500000
output[0, 0, 0, 1] = 6.000000
...
output[0, 0, 0, 10] = 10.500000
output[0, 0, 0, 0] = 22.000000
...
output[0, 1, 1, 10] = 1664.000000
The coordinate [0, 0, 0, 0]
repeats multiple times, but the coordinate [1, 0, 0, 0]
is missing.
The results are completely incorrect either. The generated kernel completely ignores the +=
operator and leaks the memory of the data already stored in C
.
Minimal reproducible example
I have provided a minimal reproducible example at: https://gist.github.com/m13253/68880026fba40b65936287fbe08766ce
The minimal reproducible example contains four files:
main.c # Main file
output_correct.txt # What the output should be, produced using NumPy
output_wrong.txt # What TACO actually produces
taco_tensor_t.h # Copied from taco/include/taco/taco_tensor_t.h
Reference commands to build and run the example:
git clone https://gist.github.com/68880026fba40b65936287fbe08766ce.git taco-bug
cd taco-bug
gcc -g -o main -std=c99 -O0 -Wall -Wextra main.c
valgrind --leak-check=full --log-file=leak-check.txt ./main > output.txt
cat output.txt # Check output tensor
cat leak-check.txt # Check memory leak report