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

Templatise Fill_cpu() and Fill_gpu() and increase block size #507

Merged
merged 3 commits into from
Nov 19, 2024

Conversation

IvanaGyro
Copy link
Collaborator

This PR is a task listed in #500.

Copy link

codecov bot commented Nov 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 18.00%. Comparing base (72453ca) to head (eed01c2).
Report is 50 commits behind head on dev-master.

Additional details and impacted files
@@              Coverage Diff               @@
##           dev-master     #507      +/-   ##
==============================================
+ Coverage       16.60%   18.00%   +1.39%     
==============================================
  Files             221      221              
  Lines           48490    52808    +4318     
  Branches        20272    19698     -574     
==============================================
+ Hits             8053     9508    +1455     
- Misses          36143    38778    +2635     
- Partials         4294     4522     +228     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@IvanaGyro IvanaGyro mentioned this pull request Nov 10, 2024
This is the preparation for refactoring the `Storage` classes.
The maximum x- or y-dimension of a block is 1024 with compute
capability above 2.x. The compute capability requirements of cuTENSOR
and cuQuantum are much higher than 2.x. Furthermore, it's not easy to
find a device that only supports the compute capability below or eqaul
1.3.
Dynamic scheduling is 1000 times slower than the static scheduling in
this case. Below is the result and the code for benchmarking.

```
Total time for FillCpu: 0.0185553 seconds
Total time for FillCpuDynamic: 21.2537 seconds
```

```cpp
/** compile command: g++ -std=c++17 -fopenmp -O3 -o fill.o fill.cpp && ./fill.o */

using namespace std;

template <typename DType>
void FillCpu(void *first, const DType &value, size_t count) {
  DType *typed_first = reinterpret_cast<DType *>(first);
  for (int i = 0; i < count; ++i) {
    typed_first[i] = value;
  }
}

template <typename DType>
void FillCpuDynamic(void *first, const DType &value, size_t count) {
  DType *typed_first = reinterpret_cast<DType *>(first);
  for (int i = 0; i < count; ++i) {
    typed_first[i] = value;
  }
}

int main() {
  int count = 100000;
  int num_iterations = 10000;
  int *ptr = reinterpret_cast<int *>(malloc(sizeof(int) * count));
  int value = 10;

  {
    auto start = chrono::high_resolution_clock::now();
    for (int iter = 0; iter < num_iterations; ++iter) {
      FillCpu(reinterpret_cast<void *>(ptr), value, count);
    }
    auto end = chrono::high_resolution_clock::now();
    const std::chrono::duration<double> total_time = end - start;
    cout << "Total time for FillCpu: " << total_time.count() << " seconds" << endl;
  }

  {
    auto start = chrono::high_resolution_clock::now();
    for (int iter = 0; iter < num_iterations; ++iter) {
      FillCpuDynamic(reinterpret_cast<void *>(ptr), value, count);
    }
    auto end = chrono::high_resolution_clock::now();
    const std::chrono::duration<double> total_time = end - start;
    cout << "Total time for FillCpuDynamic: " << total_time.count() << " seconds" << endl;
  }
}
```
@IvanaGyro IvanaGyro merged commit 7fd2551 into dev-master Nov 19, 2024
4 checks passed
@IvanaGyro IvanaGyro deleted the templatise_fill branch November 19, 2024 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants