Intel® oneAPI Data Parallel C++
Support for Intel® oneAPI DPC++ Compiler, Intel® oneAPI DPC++ Library, Intel ICX Compiler , Intel® DPC++ Compatibility Tool, and GDB*
581 Discussions

The code in parallel_for is not covered by llvm code coverage

Paavan_Joshi
Employee
1,448 Views

Hi Team,

 

I tried to generate a code coverage report for my DPC++ code using llvm, but it is not displaying the correct result, even if each line of code is running.

Following some debugging, I discovered that it is not covering specific code under parallel for.

Sample code:-

main.cpp

 

#include <CL/sycl.hpp>
#include <iostream>
using namespace std;
using namespace sycl;
const std::string secret {
    "Ifmmp-!xpsme\"\012J(n!tpssz-!Ebwf/!"
        "J(n!bgsbje!J!dbo(u!ep!uibu/!.!IBM\01"};
const auto sz = secret.size();
int main() {
    queue Q;
    char*result = malloc_shared<char>(sz, Q);
    std::memcpy(result,secret.data(),sz);
    Q.parallel_for(sz,[=](auto&i) {
        // Temp/extra code start(This is added to increase code inside parallel_for)
        result[i] -= 1;
        result[i] += 1;
        result[i] -= 1;
        result[i] += 1;
        result[i] -= 1;
        result[i] += 1;
        // Temp/extra code end..
        result[i] -= 1;
        });
    Q.wait();
    std::cout << result << "\n";
    return 0;
}

 

makefile

 

CC  = dpcpp
CFLAG = -fprofile-instr-generate -fcoverage-mapping
RM  = rm -rf
export LLVM__ROOT = /opt/intel/oneapi/compiler/2022.1.0/linux/bin-llvm
help: ## Makefile help
	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
main.o: main.cpp
	$(CC) $(CFLAG) -c -Wall  main.cpp
build: main.o ## Make build
	$(CC) $(CFLAG) -o main main.o
coverage: ## Run code coverage
	LLVM_PROFILE_FILE="main.profraw" ./main
	$(LLVM__ROOT)/llvm-profdata merge -sparse main.profraw -o main.profdata
	$(LLVM__ROOT)/llvm-cov report ./main -instr-profile=main.profdata
clean: ## Clean all generate files
	$(RM) main *.o *.profdata *.profraw

 

Steps to generate code coverage,

$ make build
$ ./main
$ make coverage

Code coverage report :-

Filename                      Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
main-0fb086.cpp                     2                 1    50.00%           2                 1    50.00%          26                 9    65.38%           0                 0         -
main-header-16a1df.h                8                 4    50.00%           8                 4    50.00%          12                 6    50.00%           0                 0         -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                              10                 5    50.00%          10                 5    50.00%          38                15    60.53%           0                 0         -

Paavan_Joshi_0-1673415286003.png

 

Could anyone help with identifying the problem and solution, please?

Labels (1)
0 Kudos
8 Replies
VarshaS_Intel
Moderator
1,412 Views

Hi,

 

Thanks for posting in Intel Communities.

 

Could you please let us know the OS details, CPU, and GPU details you are using? 

 

And also, could you please let us know on which device selector you are using by using the below command?

SYCL_PI_TRACE=1 ./main (./main is the executable that got generated)

 

>>but it is not displaying the correct result, even if each line of code is running.

Could you please let us know what are the expected results?

 

Thanks & Regards,

Varsha

 

0 Kudos
Paavan_Joshi
Employee
1,365 Views

Hi Varsha,

 

>> Could you please let us know the OS details, CPU, and GPU details you are using? 

- The output of clinfo is stored to a file and attached to the reply.

OS :- Ubuntu 20.04.5 LTS

cat /proc/cpuinfo

vendor_id : GenuineIntel
cpu family : 6
model : 190
model name : Genuine Intel(R) 0000

 

>> And also, could you please let us know on which device selector you are using by using the below command?

 

SYCL_PI_TRACE=1 ./main (./main is the executable that got generated)

 


 

SYCL_PI_TRACE[basic]: Plugin found and successfully loaded: libpi_opencl.so
SYCL_PI_TRACE[all]: Selected device ->
SYCL_PI_TRACE[all]:   platform: Intel(R) OpenCL HD Graphics
SYCL_PI_TRACE[all]:   device: Intel(R) Graphics [0x46d1]
Hello, world!   I'm sorry, Dave. I'm afraid I can't do that. - HAL

 

->  cout << "Running on " << Q.get_device().get_info<info::device::name>()<< "\n";

 

Running on Intel(R) Graphics [0x46d1]

 

 

>> Could you please let us know what are the expected results?

As all the lines of main is executed, it should shows cover as 100% (for now its shoes as 50%). 

 

Thanks & Regards,

Paavan

0 Kudos
VarshaS_Intel
Moderator
1,324 Views

Hi,


Thanks for providing the details.


The code coverage percentage shown by the general commands might not be significant. We should not read it as an absolute value of how much the "original" source codes have been covered. 


>>As all the lines of main is executed, it should shows cover as 100% (for now its shoes as 50%). 

And also, the compiler generates a lot of extra codes including the codes from the header files. So, the code coverage percentage will be generated based on all the lines of code generated by the compiler.


I hope this helps resolve your query. 


Thanks & Regards,

Varsha


0 Kudos
Paavan_Joshi
Employee
1,300 Views

Hi Varsha

 

However, even if I add more lines of code inside a particular parallel_for, the percentage of code coverage will still decrease.

Please check the attached screenshots:-

1 line of code inside parallel_for :- 

COVERAGE_1_PARALLEL_FOR_LINES.TXT.jpg

                  - covers :- 80% of code.

7 lines of code inside parallel_for :- 

COVERAGE_7_PARALLEL_FOR_LINES.TXT.jpg

                - covers :- 66.67% of code.

13 lines of code inside parallel_for :- 

COVERAGE_13_PARALLEL_FOR_LINES.TXT.jpg

                - covers :- 61.54% of code.

As a result of this discovery, I have a suspicion that it is not covering a certain parallel_for area of the code.

 

Thanks & Regards,

Paavan

 

0 Kudos
VarshaS_Intel
Moderator
1,153 Views

Hi,


Could you please provide us with any update on your issue(we have contacted you internally through the mail)?


Thanks & Regards,

Varsha


0 Kudos
Paavan_Joshi
Employee
1,146 Views

Hi Varsha,

 

Replied back on same mail chain, please check.

>>  As I am facing this issue on some project and that’s why I am using ADL-S/ADL-N board itself not intel OneCloud.

>>  The problem is that, the code coverage itself doesn’t covers code inside parallel_for at all. Is there any way to cover that.

 

Can we connect on teams so we can discuss and look into it quickly? 

 

Thanks and Regards,

Paavan 

0 Kudos
VarshaS_Intel
Moderator
1,027 Views

Hi,


Thanks for your patience.


Apologies for the delay in my response. As Intel Code Coverage inherits the feature of the open source llvm.org(https://clang.llvm.org/docs/SourceBasedCodeCoverage.html).


Sorry for the inconvenience caused to you. As the issue is related to Clang Code Coverage so we suggest you file an issue on llvm.org GitHub (https://github.com/llvm/llvm-project/issues/).


Could you please let us know if you have any other queries related to Intel Compiler? If not, can we go ahead and close this thread?


Thanks & Regards,

Varsha


0 Kudos
VarshaS_Intel
Moderator
1,003 Views

Hi,


We have not heard back from you. This thread will no longer be monitored by Intel. If you need additional information, please start a new thread.


Thanks & Regards,

Varsha


0 Kudos
Reply