This commit is contained in:
JOLIMAITRE Matthieu 2024-03-28 17:58:33 +01:00
parent 8b3bb9c382
commit d976cfaf74
37 changed files with 2669 additions and 371 deletions

66
gpu/tp4/c/src/ex1.cu Normal file
View file

@ -0,0 +1,66 @@
#include "conv.h"
void print(const std::vector<int>& vec) {
if (vec.empty()) {
std::cout << "[]" << std::endl;
} else {
std::cout << "[";
for (size_t i = 0; i < vec.size() - 1; ++i) std::cout << vec[i] << ", ";
std::cout << vec.back() << "]" << std::endl;
}
}
int main() {
{
std::cout << "Test 1" << std::endl;
const auto x = std::vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // N = 10
const auto y = std::vector{0, 1, 0}; // M = 3
const auto z_sol = std::vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const auto z = conv1(x, y);
if (z != z_sol) {
std::cout << "Error, expected:" << std::endl;
print(z_sol);
std::cout << "got:" << std::endl;
print(z);
} else {
std::cout << "Ok" << std::endl;
}
}
{
std::cout << "Test 2" << std::endl;
const auto x = std::vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // N = 10
const auto y = std::vector{1, 2, 4, 2, 1}; // M = 5
const auto z_sol = std::vector{4, 11, 20, 30, 40, 50, 60, 70, 70, 59};
const auto z = conv1(x, y);
if (z != z_sol) {
std::cout << "Error, expected:" << std::endl;
print(z_sol);
std::cout << "got:" << std::endl;
print(z);
} else {
std::cout << "Ok" << std::endl;
}
}
{
std::cout << "Test 3" << std::endl;
const auto x = std::vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34}; // N = 35
const auto y =
std::vector{1, -2, 4, -8, 16, -32, 64, -128, 256, -1024, 256, -128, 64, -32, 16, -8, 4, -2, 1}; // M = 19
const auto z_sol =
std::vector{117, -736, -1333, -2058, -2719, -3412, -4089, -4774, -5455, -6138, -6820, -7502,
-8184, -8866, -9548, -10230, -10912, -11594, -12276, -12958, -13640, -14322, -15004, -15686,
-16368, -17050, -17767, -18380, -19201, -19606, -20843, -20416, -23317, -19562, -29119};
const auto z = conv1(x, y);
if (z != z_sol) {
std::cout << "Error, expected:" << std::endl;
print(z_sol);
std::cout << "got:" << std::endl;
print(z);
} else {
std::cout << "Ok" << std::endl;
}
}
return 0;
}