operations_matrix_cuda_test
import os
import sys
import numpy as np
# ✅ 프로젝트 루트(dev/)를 sys.path에 추가
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..")))
# ✅ 공통 테스트 설정 임포트
from tests.test_setup import setup_paths, import_cuda_module
setup_paths()
operations_matrix_cuda = import_cuda_module()
# ✅ 올바른 경로로 import 수정
from cal_graph.core_graph import Cal_graph
def test_connect_graphs():
cal_graph = Cal_graph()
A = [[1, 2], [3, 4]]
B = [[10, 20], [30, 40]]
result1, _ = operations_matrix_cuda.matrix_multiply(
np.array(A, dtype=np.float64),
np.array(B, dtype=np.float64)
)
result1_list = result1.tolist()
node_list1 = cal_graph.add_matrix_multiply_graph(A, B, result1_list)
C = [[1, 2], [3, 4]]
result2, _ = operations_matrix_cuda.matrix_add(
np.array(result1_list, dtype=np.float64),
np.array(C, dtype=np.float64)
)
result2_list = result2.tolist()
node_list2 = cal_graph.add_matrix_add_graph(result1_list, C, result2_list)
cal_graph.connect_graphs(node_list2, node_list1)
cal_graph.print_graph()
print("result2_list =", result2_list)
expected = np.array(A) @ np.array(B) + np.array(C)
assert np.allclose(np.array(result2_list), expected), f"Expected {expected.tolist()}, got {result2_list}"
if __name__ == "__main__":
test_connect_graphs()
디렉터리 구조 중
AI_framework-dev/
└── dev/
├── backend/
│ └── operaters/
│ └── tests/
│ └── operations_matrix_cuda_test.py ✅ 현재 실행 중
├── cal_graph/
│ └── core_graph.py ✅ Cal_graph 클래스 정의
└── tests/
├── test_setup.py ✅ 경로/모듈 초기화 유틸
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..")))
sys.path 에 프로젝트 루트 등록, 이를 통해
dev/ 안의 모듈들을 인식 가능하도록 한다.
공통 테스트 환경 초기화 함수
from tests.test_setup import setup_paths, import_cuda_module
setup_paths()
operations_matrix_cuda = import_cuda_module()
test_setup.py 안에서 공통으로 수행하는 작업
setup_paths() : Pybind 로 빌드된 .pyd 모듈 경로 추가
CUDA DLL 경로를 시스템에 등록
일반 python import 경로 정리
import operations_matrix_cuda 시도
각 테스트 파일에서 중복 설정 제거
dev/ 폴더가 sys.path 에 추가되어 있으므로 cal_graph.core_graph 로 import 가능
내부 core_graph.py 파일은 상대 import 를 사용해야 직접 실행도 호환된다.
[operations_matrix_cuda_test.py]
↓
setup_paths()
├─ sys.path ← dev 추가
├─ CUDA DLL 등록
└─ operations_matrix_cuda 경로 등록
↓
from cal_graph.core_graph import Cal_graph
↓
Cal_graph 내의 상대 import (.node, .graph_utils 등) 동작
'dev_AI_framework' 카테고리의 다른 글
CUDA 연산 모듈 (.pyd) 이 Python 에서 import 되지 않음 (0) | 2025.04.10 |
---|---|
디렉토리 구조 리팩토링 (0) | 2025.04.08 |
pytest (0) | 2025.04.07 |
4.1 판별 함수 - 다중 클래스 (0) | 2025.04.06 |
지금까지 구현 내용 정리 및 앞으로의 계획 (0) | 2025.03.31 |